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

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

First of all you should build the Qt plugin that provides all custom widgets of FreeCAD we need for the Qt Designer. The sources are located under //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 your Qt Designer you have to copy the file to //$QTDIR/plugin/designer//.

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. python libcoin40-dev libsoqt-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 libumfpack4-dev optionally you can also install libsimage-dev to make Coin to support additinal image file formats

However there are a few inconveniences for the following libraries


 * OpenCASCADE

For OpenCASCADE there does not exist an official .deb package so you have to 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

The official Debian package for SoQt depends on Qt3, but we need SoQt to depend on Qt4. To achieve that get a source tarball from coin.org and unpack it. Build the binaries with ./configure --prefix=/usr --with-qt=/usr/share/qt4 make and replace the files with the new ones
 * libSoQt.so.20.x.y
 * /usr/lib/libSoQt.la
 * /usr/share/Coin/conf/soqt-default.cfg

Configuration
If you have get 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 type make into your console.

If any bugs 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.

Compile FreeCAD
After fulfilling all prerequisites compiling FreeCAD is as simple as make 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.

Compile on Ubuntu 64 bits
Compiling on a 64-bit machine is a bit tricky but it works fine. This explanation assumes you can download from a svn repository, install ubuntu packages and that you know how to cope with the maybe necessary permissions/sudo/chown stuff. Also, read the first part here above first.

Pre-compiled Libraries / Ubuntu packages
You need all the FreeCAD Third Party Libraries correctly installed before compiling, and also a few other libraries needed by OpenCascade, like tcl/tk. Most of the libraries are availible via apt-get or synaptic package manager. You probably have several of them already installed... For most of them you need the library and its "dev" package which contains files used when you compile your own programs: python libqt4 libqt4-dev libcoin40c2 libcoin40-dev libsoqt20 libsoqt-dev libxerces27 libxerces27-dev libgts-0.7-1 libgts-dev 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) libcv1 libcv-dev libhighgui1 libhighgui-dev libboost*

The last one, the boost library, is not provided as a single package, but in several (about 20) small packages. If you use synaptic, mark all packages that begin with "libboost".

As you see, several of those libraries have their version number in the package name. Those are the most recent versions at the time I am writing this. So maybe you can find more recent versions, which should work too.

Libraries you need to compile yourself

 * WildMagic3

Since FreeCAD 0.7 the Wildemagic code is incorporated in the FreeCAD source, so no need to bother with it anymore!


 * OpenCASCADE

This is a bit more difficult. The package you download from opencascade.org contains 32bit-compiled libraries, which we won't use, and the sources, which we will use. Before anything, be aware that you will need several (>7) Gigabytes free at the moment you compile.

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

Once the package is installed, go into path_where_you_installed_opencascade/ros

EDIT: 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, come back here, edit the "configure" script, locate the CXXFLAGS="$CXXFLAGS " statement, and replace it by CXXFLAGS="$CXXFLAGS -ffriend-injection -fpermissive". Then do all the following steps again.

Now execute ./configure --with-tcl=/usr/lib/tcl8.4 --with-tk=/usr/lib/tk8.4 If you start building now, 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 Now you can build. Go back to the ros folder and do: make It will take a long time, maybe several hours. 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. Now clean up the enormous temporary compilation files by doing make clean

As an alternative, if you don't like to "make install" things in your well maintained ubuntu system, there are programs (checkinstall, for exemple) that will create a .deb package while installing, so you can uninstall it easily later.

Automake macros
The configure script of FreeCAD makes use of several automake macros that seem not to be installed with their packages: bnv_have_qt.m4, coin.m4, and gts.m4. If needed, 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

Compile FreeCAD
First, open a terminal and go to the folder where you downloaded the FreeCAD sources. Then, deploy your armies: ./autogen.sh This will create the configure script, then automake This will create the Makefile templates Then, just run configure with ./configure --with-OCC-includes=PATH_TO_OPENCASCADE/ros/inc --with-OCC-libs=/usr/local/lib Then, if the configure script didn't complain about anything, do make and if all went successfully, make install Your program will be waiting in Your_home_folder/FreeCAD/bin. If you really need, you can now delete the opencascade folder, since the libraries are in /usr/local/lib, and the headers are only used when compiling. But I would recommend to keep it, for compiling again in the future, when new versions of FreeCAD will come out...

Another alternative (what I did on my system) is to copy all the opencascade headers to a new folder inside /usr/include so you can delete the opencascade folder and still keep all that's needed to compile freeCAD again (the libraries and the headers).

If you need the qt designer plugin (only needed if you intend to develop stuff for FreeCAD) then go to the Tools/plugin/widget folder and build the widget as described in the CompileOnUnix section. Copy it in /usr/libs/qt4/plugin/designer.