Openscad Manual 11

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

OpenSCAD User Manual/Print version - Wikibooks, o... http://en.wikibooks.org/w/index.php?title=OpenSCA...

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

NetBSD 5.x, requires a patched version of CGAL. It is recommended to upgrade to NetBSD 6


instead as it has all dependencies available from pkgin. NetBSD also requires the X Sets to
be installed when the system was created (or added later (http://ghantoos.org/2009/05
/12/my-first-shot-of-netbsd/)).

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).

Test suite problems

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:

$ Xvfb :5 -screen 0 800x600x24 &


$ DISPLAY=:5 ctest

Alternatively:

$ xvfb-run --server-args='-screen 0 800x600x24' ctest

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'

108 sur 128 11/03/2014 10:03


OpenSCAD User Manual/Print version - Wikibooks, o... http://en.wikibooks.org/w/index.php?title=OpenSCA...

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

Your version of imagemagick is old. Upgrade imagemagick, or pass -DCOMPARATOR=old to


cmake. The comparison will be of lowered reliability.

I moved the dependencies I built and now openscad won't run

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.

Tricks and tips


Reduce space of dependency build

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

OpenSCAD's config file is kept in ~/.config/OpenSCAD/OpenSCAD.conf.

Setup environment to start developing OpenSCAD in Ubuntu 11.04

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.

Add required PPA repositories:

# sudo add-apt-repository ppa:chrysn/openscad

Update and install required packages:

109 sur 128 11/03/2014 10:03


OpenSCAD User Manual/Print version - Wikibooks, o... http://en.wikibooks.org/w/index.php?title=OpenSCA...

# sudo apt-get update


# sudo apt-get install git build-essential qtcreator libglew1.5-dev libopencsg-dev libcgal-dev libeigen2-dev

Get the OpenSCAD sources:

# mkdir ~/src
# cd ~/src
# git clone https://github.com/openscad/openscad.git

Build OpenSCAD using the command line:

# cd ~/src/openscad
# qmake
# make

Build OpenSCAD using QT Creator:

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).

The Clang Compiler

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.

source scripts/setenv-unibuild.sh clang

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:

110 sur 128 11/03/2014 10:03


OpenSCAD User Manual/Print version - Wikibooks, o... http://en.wikibooks.org/w/index.php?title=OpenSCA...

git clone https://github.com/openscad/openscad.git


cd openscad
source ./scripts/setenv-mingw-xbuild.sh
./scripts/mingw-x-build-dependencies.sh
./scripts/release-common.sh mingw32

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:

git clone git://github.com/mxe/mxe.git

Add the following line to your ~/.bashrc file:

export PATH=/<where mxe is installed>/usr/bin:$PATH

replacing <where mxe is installed> with the appropriate path.

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:

111 sur 128 11/03/2014 10:03


OpenSCAD User Manual/Print version - Wikibooks, o... http://en.wikibooks.org/w/index.php?title=OpenSCA...

make mpfr eigen opencsg cgal qt

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:

git clone git://github.com/openscad/openscad.git


cd openscad

Then get MCAD:

git submodule init


git submodule update

You need to create a symbolic link here for the build system to find the libraries:

ln -s /<where mxe is installed>/usr/i686-pc-mingw32/ mingw-cross-env

again replacing <where mxe is installed> with the appropriate path

Now to build OpenSCAD run:

i686-pc-mingw32-qmake CONFIG+=mingw-cross-env openscad.pro


make

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

112 sur 128 11/03/2014 10:03


OpenSCAD User Manual/Print version - Wikibooks, o... http://en.wikibooks.org/w/index.php?title=OpenSCA...

Note that as of early 2013, OpenSCAD's 'scripts/release-common.sh' automatically uses the


version of nsis that comes with the MXE cross build system, so you may wish to investigate
the release-common.sh source code to see how it works, if you have troubles. This is a set of
instructions for building OpenSCAD with the Microsoft Visual C++ compilers.

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:

Visual Studio Express http://download.microsoft.com/download/E/8/E


/E8EEB394-7F42-4963-A2D8-29559B738298/VS2008ExpressWithSP1ENUX1504728.iso
QT (for vs2008) http://get.qt.nokia.com/qt/source/qt-win-opensource-4.7.2-vs2008.exe
git http://msysgit.googlecode.com/files/Git-1.7.4-preview20110204.exe
glew https://sourceforge.net/projects/glew/files/glew/1.5.8/glew-1.5.8-win32.zip
/download
cmake http://www.cmake.org/files/v2.8/cmake-2.8.4-win32-x86.exe
boost http://www.boostpro.com/download/boost_1_46_1_setup.exe
cgal https://gforge.inria.fr/frs/download.php/27647/CGAL-3.7-Setup.exe
OpenCSG http://www.opencsg.org/OpenCSG-1.3.2.tar.gz
eigen2 http://bitbucket.org/eigen/eigen/get/2.0.15.zip
gmp/mpfr http://holoborodko.com/pavel/downloads/win32_gmp_mpfr.zip
MinGW http://netcologne.dl.sourceforge.net/project/mingw
/Automated%20MinGW%20Installer/mingw-get-inst/mingw-get-inst-20110316/mingw-
get-inst-20110316.exe

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

113 sur 128 11/03/2014 10:03


OpenSCAD User Manual/Print version - Wikibooks, o... http://en.wikibooks.org/w/index.php?title=OpenSCA...

Install to default location C:\Program Files\CMake 2.8


Install Boost
Select the VC++ 9.0 vs2008 radio
Check the 'multithreaded static runtime' checkbox only
Install into C:\boost_1_46_1\
Install CGAL
Note - CGAL 3.9 fixes several bugs in earlier versions of CGAL, but CGAL 3.9 will
not compile under MSVC without extensive patching. Please keep that in mind
when compiling OpenSCAD with MSVC - there may be bugs due to the outdated
version of CGAL required to use MSVC.
Note its not a binary distribution, just an installer that installs the source.
No need for CGAL Examples and Demos
Make sure mpfr and gmp precompiled libs is checked
The installer wants you to put this in C:\Program Files\CGAL-3.7\ I used C:\CGAL-3.7\
Make sure CGAL_DIR environment checked.
Install MinGW
Make sure you select the MSYS Basic System under components
Extract downloaded win32_gmp_mpfr.zip file to C:\win32_gmp_mpfr\
Replace the mpfr and gmp .h files in CGAL with the ones from win32_gmp_mpfr
Delete, or move to a temp folder, all files in CGAL-3.7\auxiliary\gmp\include folder
Copy all the .h files in C:\win32_gmp_mpfr\gmp\Win32\Release to CGAL-3.7\auxiliary
\gmp\include
Copy all the .h files in C:\win32_gmp_mpfr\mpfr\Win32\Release to CGAL-3.7\auxiliary
\gmp\include
Replace the mpfr and gmp libs in CGAL with the ones from win32_gmp_mpfr
Delete, or move to a temp folder, all (06/20/2011 libmpfr-4.lib is needed 7/19/11 - i
didnt need it) files in CGAL-3.7\auxiliary\gmp\lib folder.
Copy C:\win32_gmp_mpfr\gmp\Win32\Release\gmp.lib to CGAL-3.7\auxiliary\gmp\lib
Copy C:\win32_gmp_mpfr\mpfr\Win32\Release\mpfr.lib to CGAL-3.7\auxiliary\gmp\lib
Go into CGAL-3.7\auxiliary\gmp\lib and copy gmp.lib to gmp-vc90-mt-s.lib, and mpfr.lib
to mpfr-vc90-mt-s.lib (so the linker can find them in the final link of openscad.exe)

To get OpenSCAD source code:

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\

Where to put other files:

I put all the dependencies in C:\ so for example,

C:\eigen2\
C:\glew-1.5.8\
C:\OpenCSG-1.3.2\

114 sur 128 11/03/2014 10:03


OpenSCAD User Manual/Print version - Wikibooks, o... http://en.wikibooks.org/w/index.php?title=OpenSCA...

.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

Start->Program Files->Qt by Nokia v4.7.2 (VS2008 OpenSource)->QT 4.7.2 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 -static -platform win32-msvc2008 -no-webkit

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

Change Debug to Release. Now re-run cmake

cmake .

It should scroll by, watch for lines saying "--Building static libraries" and "--Build type:

115 sur 128 11/03/2014 10:03


OpenSCAD User Manual/Print version - Wikibooks, o... http://en.wikibooks.org/w/index.php?title=OpenSCA...

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

Launch Visual Express.

cd C:\OpenCSG-1.3.2
vcexpress OpenCSG.sln
Substitute devenv for vcexpress if you are not using the express version

Manually step through project upgrade wizard


Make sure the runtime library settings for all projects is for Release (not Debug)
Click Build/Configuration Manager
Select "Release" from "Configuration:" drop down menu
Hit Close
Make sure the runtime library setting for OpenCSG project is set to multi-threaded
static
Open the OpenCSG project properties by clicking menu item "Project->OpenCSG
Properties" (might be just "Properties")
Make sure it says "Active(Release)" in the "Configuration:" drop down menu
Click 'Configuration Properties -> C/C++ -> Code Generation'
Make sure "Runtime Library" is set to "Multi-threaded (/MT)"
Click hit OK
Make sure the runtime library setting for glew_static project is set to multi-threaded
static
In "Solution Explorer - OpenCSG" pane click "glew_static" project
Open the OpenCSG project properties by clicking menu item "Project->OpenCSG
Properties" (might be just "Properties")
Make sure it says "Active(Release)" in the "Configuration:" drop down menu
Click C/C++ -> Code Generation
Make sure "Runtime Library" is set to "Multi-threaded (/MT)"
Click hit OK
Close Visual Express saving changes

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:

cmd /c vcexpress OpenCSG.sln /build


Again, substitute devenv if you have the full visual studio

116 sur 128 11/03/2014 10:03


OpenSCAD User Manual/Print version - Wikibooks, o... http://en.wikibooks.org/w/index.php?title=OpenSCA...

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

Open the QT Shell, and copy/paste the following commands

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.

Compiling the regression tests


Follow all the above steps, build openscad, run it, and test that it basically works.
Install Python 2.x (not 3.x) from http://www.python.org
Install Imagemagick from http://www.imagemagick.org
read openscad\docs\testing.txt
Go into your QT shell

set PATH=%PATH%;C:\Python27 (or your version of python)


cd c:\openscad\tests\
cmake . -DCMAKE_BUILD_TYPE=Release
Edit the CMakeCache.txt file, search/replace /MD to /MT
cmake .

117 sur 128 11/03/2014 10:03


OpenSCAD User Manual/Print version - Wikibooks, o... http://en.wikibooks.org/w/index.php?title=OpenSCA...

nmake -f Makefile

This should produce a number of test .exe files in your directory. Now run

ctest

If you have link problems, see Troubleshooting, below.

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

nmake -f Makefile.Release > log.txt

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:

compiler switch - type - linked runtime C library


/MT - Multithreaded static Release - link to LIBCMT.lib
/MTd - Multithreaded static Debug - link to LIBCMTD.lib
/MD - Multithreaded DLL Release - link to MSVCRT.lib (which itself helps link to the DLL)
/MDd - Multithreaded DLL Debug - link to MSVCRTD.lib (which itself helps link to the DLL)

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

118 sur 128 11/03/2014 10:03

You might also like