CompileOnUnix

Compile on Linux
Before you get too bogged down in details, here is a script that you can use to follow along: DebianScript

If you find anything wrong, please correct it.

Get Source
Before you can compile FreeCAD, you must get the source code. First install subversion. Then, in the appropriate directory, do: svn co https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk freecad This will give you an anonymous checkout of the current development version in a new directory "freecad". Alternatively you can download a source tarball but they are already quite old so it's probably better to always get the latest sources via subversion.

Prerequisites
To compile FreeCAD under Linux you have to install all libraries mentioned in Third Party Libraries first. As compiler you should have installed gcc in a version equal to 3.x.y or newer, especially g++ is needed because FreeCAD is completely written in C++. Both gcc and g++ are included in the build-essential package listed below. During the compilation some Python scripts get executed. So the Python interpreter has to work properly.

To avoid any linker problems during the build process it would be a good idea to have the library paths either in your LD_LIBRARY_PATH variable or in your ld.so.conf file. This is normally already the case in recent distributions.

For more details have also a look to README.Linux in your sources.

Prerequisites on Debian/Ubuntu
On Debian based systems it is quite easy to get all needed libraries installed. Most of the libraries are available via apt-get or synaptic package manager. Below are listed all dev packgages you need to install. build-essential python libcoin40-dev libsoqt4-dev libxerces27-dev libboost-dev libboost-date-time-dev libboost-filesystem-dev libboost-graph-dev libboost-iostreams-dev libboost-program-options-dev libboost-serialization-dev libboost-signals-dev libboost-regex-dev libgts-dev libqt4-dev qt4-dev-tools python2.5-dev libcv-dev libhighgui-dev python-opencv optionally you can also install libsimage-dev checkinstall the first one to make Coin to support additinal image file formats, the second one to register your installed files into your system's package manager, so yo can easily uninstall later.

To simply install all these libraries in one step, just copy/paste the following text in a terminal (only for debian/ubuntu based systems) as root:

 apt-get install build-essential python libcoin40-dev libsoqt4-dev libxerces27-dev libboost-dev libboost-date-time-dev libboost-filesystem-dev libboost-graph-dev libboost-iostreams-dev libboost-program-options-dev libboost-serialization-dev libboost-signals-dev libboost-regex-dev libgts-dev libqt4-dev qt4-dev-tools python2.5-dev libcv-dev libhighgui-dev python-opencv libsimage-dev checkinstall 

However there are a few inconveniences for the following libraries:


 * OpenCASCADE

For OpenCASCADE there does not exist an official .deb package. However, you can get unofficial packages from here. To build your own private packages follow these steps: wget http://lyre.mit.edu/~powell/opencascade/opencascade_6.2.0.orig.tar.gz wget http://lyre.mit.edu/~powell/opencascade/opencascade_6.2.0-7.dsc wget http://lyre.mit.edu/~powell/opencascade/opencascade_6.2.0-7.diff.gz

dpkg-source -x opencascade_6.2.0-7.dsc

sudo apt-get install build-essential devscripts debhelper autoconf automake libtool bison libx11-dev tcl8.4-dev tk8.4-dev libgl1-mesa-dev libglu1-mesa-dev java-gcj-compat-dev libxmu-dev
 * 1) Install OCC build-deps

cd opencascade-6.2.0 ; debuild
 * 1) Build Opencascade packages. This takes hours and requires
 * 2) at least 8 GB of free disk space

sudo dpkg -i libopencascade6.2-0_6.2.0-7_i386.deb libopencascade6.2-dev_6.2.0-7_i386.deb
 * 1) Install the resulting library debs

Alternatively, you can download the latest version from opencascade.org.

Install the package normally, be aware that the installer is a java program that requires the official java runtime edition from Sun (package name: sun-java6-jre), not the open-source java (gij) that is bundled with Ubuntu. Install it if needed: sudo apt-get remove gij sudo apt-get install sun-java6-jre Be careful, if you use gij java with other things like a browser plugin, they won't work anymore. If the installer doesn't work, try: java -cp path_to_file_setup.jar <-Dtemp.dir=path_to_tmp_directory> run


 * SoQt

At the time of writing this article there were only SoQt4 packages for Debian itself available but not for Ubuntu. To get the packages built do the following steps: wget http://ftp.de.debian.org/debian/pool/main/s/soqt/soqt_1.4.1.orig.tar.gz wget http://ftp.de.debian.org/debian/pool/main/s/soqt/soqt_1.4.1-4.dsc wget http://ftp.de.debian.org/debian/pool/main/s/soqt/soqt_1.4.1-4.diff.gz dpkg-source -x soqt_1.4.1-4.dsc sudo apt-get install doxygen devscripts fakeroot debhelper libqt3-mt-dev qt3-dev-tools libqt4-opengl-dev (cd soqt-1.4.1 ; debuild) sudo dpkg -i libsoqt4-20_1.4.1-4_i386.deb libsoqt4-dev_1.4.1-4_i386.deb libsoqt-dev-common_1.4.1-4_i386.deb

Compile FreeCAD
If you got the sources with subversion then the very first step must be ./autogen.sh that creates the configure script and more. Therefore you must have automake and libtool installed on your system

For the build process of FreeCAD we provide a configure script. Just type in ./configure --help to get an overview of all options you can specify. Normally you need none of them - unless you have one of your libraries installed in a really uncommon directory. After configuration has finished compiling FreeCAD is as simple as make If any error occurs while building from sources, please double-check this page and README.Linux file, then you could jump to the Bug Tracker on SourceForge, choose Any for status and click the Browse button to see previous reports on compile problems.

After having built FreeCAD successfully, with make install you can install it onto your machine.The default install directory is $(HOME)/FreeCAD so you don't need root privileges therefore.

Instead of make install, you can also do checkinstall to create an entry in your package management system, so you can uninstall easily later. But since all of FreeCAD installation resides into one directory, just removing the FreeCAD directory is a valid way to uninstall too.

Optional
If you need the Qt Designer plugin that provides all custom widgets of FreeCAD go to freecad/src/Tools/plugins/widget So far we don't provide a makefile -- but calling qmake plugin.pro creates it. Once that's done, calling make will create the library libFreeCAD_widgets.so. To make this library known to Qt Designer you have to copy the file to $QTDIR/plugin/designer

Compile on 64 bits systems
Compiling on a 64-bit machine happens basically the same way as above, but there are a couple of specific steps to do:

Additional Libraries
You need all the FreeCAD Third Party Libraries listed above, plus a couple of extra ones that are needed for compiling opencascade, usually availible in your package manager:

tcl8.4 (needed only by opencascade) tcl8.4-dev (needed only by opencascade) tk8.4 (needed only by opencascade) tk8.4-dev (needed only by opencascade)

Compiling OpenCascade
The Opencascade you downloaded above contains libraries compiled in 32 bits and the sources, which we will use to recompile the libraries in 64 bits. Before anything, be aware that you will need several (>7) Gigabytes free at the moment you compile.

Install the package normally as described above.

Once the package is installed, go into the "ros" directory inside the opencascade dir, and do ./configure --with-tcl=/usr/lib/tcl8.4 --with-tk=/usr/lib/tk8.4 Now you can build. Go back to the ros folder and do: make It will take a long time, maybe several hours.

Possible error 1: If you are using OCC version 6.2, it is likely that the compiler will stop right after the beginning of the "make" operation. If it happens, edit the "configure" script, locate the CXXFLAGS="$CXXFLAGS " statement, and replace it by CXXFLAGS="$CXXFLAGS -ffriend-injection -fpermissive". Then do the configure step again.

Possible error 2: Possibly several modules (WOKSH, WOKLibs, TKWOKTcl, TKViewerTest and TKDraw) will complain that they couldn't find the tcl/tk headers. In that case, since the option is not offered in the configure script, you will have to edit manually the makefile of each of those modules: Go into adm/make and into each of the bad modules folders. Edit the Makefile, and locate the lines CSF_TclLibs_INCLUDES = -I/usr/include and CSF_TclTkLibs_INCLUDES = -I/usr/include and add /tcl8.4 and /tk8.4 to it so they read: CSF_TclLibs_INCLUDES = -I/usr/include/tcl8.4 and CSF_TclTkLibs_INCLUDES = -I/usr/include/tk8.4

When it is done, just install by doing sudo make install The library files will be copied into /usr/local/lib which is fine because there they will be found automatically by any program. Alternatively, you can also do sudo checkinstall which will do the same as make install but create an entry in your package management system so you can easily uninstall later. Now clean up the enormous temporary compilation files by doing make clean

Now you just need to compile freeCAD the same way as described above.

Troubleshooting
The configure script of FreeCAD makes use of several automake macros that are sometimes not installed with their packages: bnv_have_qt.m4, coin.m4, and gts.m4. If needed (error while configuring), google for them and you will find them easily. They are just simple scripts that you need to put in your /usr/share/aclocal folder.
 * Automake macros

Standard way
If you plan to build a Debian package out of the sources you need to install further packages first. Required are dh-make fakeroot and optional but recommended is lintian To build a package open a console, go to the FreeCAD directory and call make debian-package Once the package is built with lintian you can check for errors in it.

Checkinstall way
Another way to simply create a debian package is to use checkinstall instead of make install. This will create a .deb package and install it, instead of just installing the files. That way, a new entry will be added to your installed packages list, so you can easily uninstall later. The created .deb will also be lying in your compilation dir, and can be used to install on other machines. There is also an automatic deb package creation script availible.