Openscad Manual 11
Openscad Manual 11
Openscad Manual 11
1.5 Gigabytes of RAM on some systems during the build of certain CGAL modules. There is
more information at StackOverflow.com (http://stackoverflow.com/questions/3634203
/why-are-templates-so-slow-to-compile).
BSD issues
The build instructions above are designed to work unchanged on FreeBSD and NetBSD.
However the BSDs typically require special environment variables set up to build any QT
project - you can set them up automatically by running
source ./scripts/setenv-unibuild.sh
On OpenBSD it may fail to build after running out of RAM. OpenSCAD requires at least 1
Gigabyte to build with GCC. You may have need to be a user with 'staff' level access or
otherwise alter required system parameters. The 'dependency build' sequence has also not
been ported to OpenBSD so you will have to rely on the standard OpenBSD system package
tools (in other words you have to have root).
Headless server
The test suite will try to automatically detect if you have an X11 DISPLAY environment
variable set. If not, it will try to automatically start Xvfb or Xvnc (virtual X framebuffers) if
they are available.
If you want to run these servers manually, you can attempt the following:
Alternatively:
There are some cases where Xvfb/Xvnc won't work. Some older versions of Xvfb may fail
and crash without warning. Sometimes Xvfb/Xvnc have been built without GLX (OpenGL)
support and OpenSCAD won't be able to generate any images.
Image-based tests takes a long time, they fail, and the log says 'return -11'
Imagemagick may have crashed while comparing the expected images to the test-run
generated (actual) images. You can try using the alternate ImageMagick comparison
method by by erasing CMakeCache, and re-running cmake with -DCOMPARATOR=ncc. This will
enable the Normalized Cross Comparison method which is more stable, but possibly less
accurate and may give false positives or negatives.
Testing images fails with 'morphology not found" for ImageMagick in the log
It isn't advised to move them because the build is using RPATH hard coded into the
openscad binary. You may try to workaround by setting the LD_LIBRARY_PATH
environment variable to place yourpath/lib first in the list of paths it searches. If all else
fails, you can re-run the entire dependency build process but export the BASEDIR
environment variable to your desired location, before you run the script to set
environment variables.
After you have built the dependencies you can free up space by removing the $BASEDIR/src
directory - where $BASEDIR defaults to $HOME/openscad_deps.
Preferences
The following paragraph describes an easy way to setup a development environment for
OpenSCAD in Ubuntu 11.04. After executing the following steps QT Creator can be used to
graphically start developing/debugging OpenSCAD.
# mkdir ~/src
# cd ~/src
# git clone https://github.com/openscad/openscad.git
# cd ~/src/openscad
# qmake
# make
Just open the project file openscad.pro (CTRL+O) in QT Creator and hit the build all
(CTRL+SHIFT+B) and run button (CTRL+R).
There is experimental support for building with the Clang compiler under linux. Clang is
faster, uses less RAM, and has different error messages than GCC. To use it, first of all you
will need CGAL of at least version 4.0.2, as prior versions have a bug that makes clang
unusable. Then, run this script before you build OpenSCAD.
Clang support depends on your system's QT installation having a clang enabled qmake.conf
file. For example, on Ubuntu, this is under /usr/share/qt4/mkspecs/unsupported/linux-
clang/qmake.conf. BSD clang-building may require a good deal of fiddling and is untested,
although eventually it is planned to move in this direction as the BSDs (not to mention OSX)
are moving towards favoring clang as their main compiler. OpenSCAD includes
convenience scripts to cross-build Windows installer binaries using the MXE system
(http://mxe.cc). If you wish to use them, you can first install the MXE Requirements such as
cmake, perl, scons, using your system's package manager (click to view a complete list of
requirements) (http://mxe.cc/#requirements). Then you can perform the following
commands to download OpenSCAD source and build a windows installer:
The x-build-dependencies process takes several hours, mostly to cross-build QT. It also
requires several gigabytes of disk space. If you have multiple CPUs you can speed up things
by running export NUMCPU=x before running the dependency build script. By default it
builds the dependencies in $HOME/openscad_deps/mxe. You can override the mxe
installation path by setting the BASEDIR environment variable before running the scripts.
The OpenSCAD binaries are built into a separate build path, openscad/mingw32.
Note that if you want to then build linux binaries, you should log out of your shell, and log
back in. The 'setenv' scripts, as of early 2013, required a 'clean' shell environment to work.
If you wish to cross-build manually, please follow the steps below and/or consult the
release-common.sh source code.
Setup
The easiest way to cross-compile OpenSCAD for Windows on Linux or Mac is to use mxe (M
cross environment). You will need to install git to get it. Once you have git, navigate to
where you want to keep the mxe files in a terminal window and run:
Requirements
The requirements to cross-compile for Windows are just the requirements of mxe. They are
listed, along with a command for installing them here (http://mxe.cc/#requirements). You
don't need to type 'make'; this will make everything and take up >10 GB of diskspace. You
can instead follow the next step to compile only what's needed for openscad.
Now that you have the requirements for mxe installed, you can build OpenSCAD's
dependencies (CGAL, Opencsg, MPFR, and Eigen2). Just open a terminal window, navigate
to your mxe installation and run:
This will take a few hours, because it has to build things like gcc, qt, and boost. Just go
calibrate your printer or something while you wait. To speed things up, you might want do
something like "make -j 4 JOBS=2" for parallel building. See the mxe tutorial (http://mxe.cc
/#tutorial) for more details.
Optional: If you want to build an installer, you need to install the nullsoft installer system.
It should be in your package manager, called "nsis".
Build OpenSCAD
Now that all the requirements have been met, all that remains is to build OpenSCAD itself.
Open a terminal window and enter:
You need to create a symbolic link here for the build system to find the libraries:
When that is finished, you will have openscad.exe in ./release and you can build an
installer with it as described in the instructions for building with Microsoft Visual C++,
described here (http://en.wikibooks.org/wiki/OpenSCAD_User_Manual
/Building_on_Windows#Building_an_installer).
The difference is that instead of right-clicking on the *.nsi file you will run:
makensis installer.nsis
The build is as static as reasonable, with no external DLL dependencies that are not
shipped with Windows
Note: It was last tested on the Dec 2011 build. Newer checkouts of OpenSCAD may not build
correctly or require extensive modification to compile under MSVC. OpenSCAD releases of
2012 were typically cross-compiled from linux using the Mingw & MXE system. See Cross-
compiling for Windows on Linux or Mac OS X.
Downloads
start by downloading:
Installing
Install Visual Studio
No need for siverlight or mssql express
You can use a virtual-CD program like MagicDisc to mount the ISO file and install
without using a CD
Install QT
Install to default location C:\Qt\4.7.2\
Install Git
Click Run Git and included Unix tools from the Windows Command Prompt despite the big
red letters warning you not to.
Install Cmake
Check the 'Add cmake to the system path for the current user' checkbox
Open "Git Bash" (or MingW Shell) (the installer may have put a shortcut on your
desktop). This launches a command line window.
Type cd c: to change the current directory.
Type git clone git://github.com/openscad/openscad.git This will put OpenSCAD
source into C:\openscad\
C:\eigen2\
C:\glew-1.5.8\
C:\OpenCSG-1.3.2\
.tgz can be extracted with tar -zxvf from the MingW shell, or Windows tools like 7-zip.
Rename and move sub-directories if needed. I.e eigen-eigen-0938af7840b0 should become
c:\eigen2, with the files like COPYING and CMakeLists.txt directly under it. c:\glew-1.5.8
should have 'include' and 'lib' directly under it.
Compiling Dependencies
For compilation I use the QT Development Command Prompt
Qt
Qt needs to be recompiled to get a static C runtime build. To do so, open the command
prompt and do:
Configure will take several minutes to finish processing. After it is done, open up the file
Qt\4.7.2\mkspecs\win32-msvc2008\qmake.conf and replace every instance of -MD with -MT.
Then:
nmake
This takes a very, very long time. Have a nap. Get something to eat. On a Pentium 4, 2.8GHZ
CPU with 1 Gigabyte RAM, Windows XP, it took more than 7 hours, (that was with -O2
turned off)
CGAL
cd C:\CGAL-3.7\
set BOOST_ROOT=C:\boost_1_46_1\
cmake .
Now edit the CMakeCache.txt file. Replace every instance of /MD with /MT . Now, look for a line
like this:
CMAKE_BUILD_TYPE:STRING=Debug
cmake .
It should scroll by, watch for lines saying "--Building static libraries" and "--Build type:
to confirm the proper settings. Also look for /MT in the CXXFLAGS line. When it's done,
Release"
you can do the build:
nmake
You should now have a CGAL-vc90-mt-s.lib file under C:\CGAL-3.7\lib . If not, see
Troubleshooting, below.
OpenCSG
cd C:\OpenCSG-1.3.2
vcexpress OpenCSG.sln
Substitute devenv for vcexpress if you are not using the express version
Build OpenCSG library. You can use the GUI Build/Build menu (the Examples project might
fail, but glew and OpenCSG should succeed). Alternatively you can use the command line:
The cmd /c bit is needed otherwise you will be returned to the shell immediately and have to
Wait for build process to complete (there will be no indication that this is happening appart
from in task manager)
OpenSCAD
Bison/Flex: Open the mingw shell and type mingw-get install msys-bison. Then do the
same for flex: mingw-get install msys-flex
cd C:\openscad
set INCLUDE=%INCLUDE%C:\CGAL-3.7\include;C:\CGAL-3.7\auxiliary\gmp\include;
set INCLUDE=%INCLUDE%C:\boost_1_46_1;C:\glew-1.5.8\include;C:\OpenCSG-1.3.2\include;C:\eigen2
set LIB=%LIB%C:\CGAL-3.7\lib;C:\CGAL-3.7\auxiliary\gmp\lib;
set LIB=%LIB%C:\boost_1_46_1\lib;C:\glew-1.5.8\lib;C:\OpenCSG-1.3.2\lib
qmake
nmake -f Makefile.Release
Wait for the nmake to end. There are usually a lot of non-fatal warnings about the linker.
On success, there will be an openscad.exe file in the release folder. Enjoy.
Building an installer
Download and install NSIS from http://nsis.sourceforge.net/Download
Put the FileAssociation.nsh macro from http://nsis.sourceforge.net/File_Association in
the NSIS Include directory, C:\Program Files\NSIS\Include
Run 'git submodule init' and 'git submodule update' to download the MCAD system
(https://github.com/elmom/MCAD) into the openscad/libraries folder.
Copy the OpenSCAD "libraries" and "examples" directory into the "release" directory
Copy OpenSCAD's "scripts/installer.nsi" to the "release" directory.
Right-click on the file and compile it with NSIS. It will spit out a nice, easy installer.
Enjoy.
nmake -f Makefile
This should produce a number of test .exe files in your directory. Now run
ctest
Troubleshooting
Linker errors
If you have errors during linking, the first step is to improve debug logging, and redirect to
a file. Open Openscad.pro and uncomment this line:
QMAKE_LFLAGS += -VERBOSE
Now rerun
You can use a program like 'less' (search with '/') or wordpad to review the log.
To debug these errors, you must understand basics about Windows linking. Windows links
to its standard C library with basic C functions like malloc(). But there are four different
ways to do this, as follows:
All of the libraries that are link together in a final executable must be compiled with the
same type of linking to the standard C library. Otherwise, you get link errors like, "LNK2005
- XXX is already defined in YYY". But how can you track down which library wasn't linked
properly? 1. Look at the log, and 2. dumpbin.exe
dumpbin.exe
dumpbin.exe can help you determine what type of linking your .lib or .obj files were
created with. For example, dumpbin.exe /all CGAL.lib | find /i "DEFAULTLIB" will give you a list
of DEFAULTLIB symbols inside of CGAL.lib. Look for LIBCMT, LIBCMTD, MSVCRT, or
MSVCRTD. That will tell you, according to the above table, whether it was built Static
Release, Static Debug, DLL Release, or DLL Debug. (DLL, of course means Dynamic Link
Library in this conversation.) This can help you track down, for example, linker errors