CompileOnUnix/it

Nelle distribuzioni Linux recenti FreeCAD si compila facilmente, dato che di solito tutte le dipendenze sono fornite dal gestore di pacchetti. Fondamentalmente si tratta di eseguire 3 passaggi:
 * 1) Ottenere il codice sorgente di FreeCAD
 * 2) Ottenere le dipendenze (i pacchetti da cui dipende FreeCAD)
 * 3) Compilare con "cmake . && make"

Qui, di seguito, troverete le spiegazioni dettagliate di tutto il processo e delle particolarità che si possono incontrare. Se trovate qualcosa di sbagliato o di non aggiornato nel testo successivo (le distribuzioni Linux cambiano spesso), o se utilizzate una distribuzione che non è elencata, per favore aiutateci a correggerlo.

Ottenere il sorgente
Per poter compilare FreeCAD è necessario il codice sorgente. Ci sono 3 modi per ottenerlo:

Git
Il modo migliore e più veloce per ottenere il codice è quello di clonare il repository git di sola lettura (bisogna avere il pacchetto git installato):

Questo crea una copia locale della versione più recente del codice sorgente di FreeCAD in una nuova directory chiamata "free-cad-code". La prima volta che si tenta la connessione a free-cad.git.sourceforge.net host, si riceve un messaggio che chiede di autenticare la chiave SSH sourceforge, che normalmente è sicura e può essere accettata (nel dubbio è possibile controllare le chiavi SSH sul sito di sourceforge)

Github
Su Github c'è un repository di FreeCAD sempre aggiornato: github.com/FreeCAD/FreeCAD_sf_master

Pacchetto sorgente
In alternativa è possibile scaricare il pacchetto sorgente, ma potrebbe già essere abbastanza vecchio, e quindi è sempre meglio ottenere i sorgenti più recenti tramite git o github.


 * Pacchetto sorgente ufficiale di FreeCAD (distribution-independent): https://sourceforge.net/projects/free-cad/files/FreeCAD%20Source/

Ottenere le dipendenze
Per compilare FreeCAD sotto Linux è necessario installare prima tutte le librerie indicate nella pagina Librerie di terze parti. Notare che i nomi e la disponibilità delle librerie dipendono dalla vostra distribuzione. Notare che se non si utilizza la versione più recente della propria distribuzione, alcuni dei pacchetti indicati in seguito potrebbero mancare dal vostro repository. In questo caso, cercare nel paragrafo sottostante dedicato alle Distribuzioni vecchie e non convenzionali.

Passa al paragrafo Compilare FreeCAD

Debian e Ubuntu
Su sistemi Debian-based (Debian, Ubuntu, Mint, etc...) è abbastanza facile ottenere tutte le dipendenze che è necessario installare. La maggior parte delle librerie sono disponibili tramite apt-get o il gestore dei pacchetti synaptic.

either:
 * build-essential
 * cmake
 * python
 * python-matplotlib
 * libtool
 * libcoin60-dev (Debian Wheezy, Wheezy-backports, Ubuntu 13.04 and before)

or:
 * libcoin80-dev (Debian unstable(Jesse), testing, Ubuntu 13.10 and forward)

either:
 * libsoqt4-dev
 * libxerces-c-dev
 * libboost-dev
 * libboost-filesystem-dev
 * libboost-regex-dev
 * libboost-program-options-dev
 * libboost-signals-dev
 * libboost-thread-dev
 * libqt4-dev
 * libqt4-opengl-dev
 * qt4-dev-tools
 * python-dev
 * python-pyside
 * pyside-tools
 * libopencascade-dev (official opencascade version)

or:
 * liboce*-dev (opencascade community edition)
 * oce-draw


 * libeigen3-dev
 * libqtwebkit-dev
 * libshiboken-dev
 * libpyside-dev
 * libode-dev
 * swig
 * libzipios++-dev
 * libfreetype6
 * libfreetype6-dev

Additional instruction for libcoin80-dev Debian wheezy-backports, unstable, testing, Ubuntu 13.10 and forward

Note that liboce*-dev includes the following libraries: You may have to install these packages by individual name.
 * liboce-foundation-dev
 * liboce-modeling-dev
 * liboce-ocaf-dev
 * liboce-visualization-dev
 * liboce-ocaf-lite-dev

Optionally you can also install these extra packages:
 * libsimage-dev (to make Coin to support additional image file formats)
 * checkinstall (to register your installed files into your system's package manager, so yo can easily uninstall later)
 * python-pivy (needed for the 2D Drafting module)
 * python-qt4 (needed for the 2D Drafting module)
 * doxygen and libcoin60-doc (if you intend to generate source code documentation)
 * libspnav-dev (for 3Dconnexion devices support like the Space Navigator or Space Pilot)

Fedora
You need the following packages:


 * gcc-c++ (or possibly another C++ compiler?)
 * cmake
 * doxygen
 * swig
 * gettext
 * dos2unix
 * desktop-file-utils
 * libXmu-devel
 * freeimage-devel
 * mesa-libGLU-devel
 * OCE-devel
 * python
 * python-devel
 * python-pyside-devel
 * pyside-tools
 * boost-devel
 * tbb-devel
 * eigen3-devel
 * qt-devel
 * qt-webkit-devel
 * ode-devel
 * xerces-c
 * xerces-c-devel
 * opencv-devel
 * smesh-devel
 * coin3-devel (if coin2 is the latest available for your version of Fedora, use packages from http://www.zultron.com/rpm-repo/ )
 * soqt-devel
 * freetype
 * freetype-devel

And optionally:


 * libspnav-devel (for 3Dconnexion devices support like the Space Navigator or Space Pilot)
 * pivy ( https://bugzilla.redhat.com/show_bug.cgi?id=458975 Pivy is not mandatory but needed for the Draft module )

Gentoo
You need the following packages to build FreeCAD:


 * dev-cpp/eigen
 * dev-games/ode
 * dev-libs/boost
 * dev-libs/xerces-c
 * dev-python/pivy
 * dev-python/PyQt4
 * media-libs/coin
 * media-libs/SoQt
 * sci-libs/opencascade-6.5
 * sys-libs/zlib
 * virtual/fortran
 * x11-libs/qt-gui
 * x11-libs/qt-opengl
 * x11-libs/qt-svg
 * x11-libs/qt-webkit
 * x11-libs/qt-xmlpatterns
 * dev-lang/swig-2.0.4-r1
 * app-admin/eselect-python-20091230
 * dev-lang/python-2.7.2-r3
 * dev-util/cmake-2.8.4
 * sys-apps/findutils-4.4.0
 * freetype

Since the latest opencascade version is not available, you might want to compile opencascade too, hence the following additional libraries are needed:
 * media-libs/ftgl
 * virtual/opengl
 * x11-libs/libXmu
 * dev-lang/tcl-8.5.9
 * dev-lang/tk-8.5.9-r1
 * dev-tcltk/itcl-3.4_beta1
 * dev-tcltk/itk-3.4_pre20090417
 * dev-tcltk/tix-8.4.3
 * x11-libs/gl2ps
 * sys-devel/automake-1.11
 * sys-devel/autoconf-2.68
 * sys-devel/libtool
 * dev-java/java-config-2.1.11-r3

OpenSUSE
You need the following packages: For FreeCAD 0.14 stable and 0.15 unstable you need to add Eigen3 and swig libraries, that don't seem to be in standard repos. You can get them with a one-click install here:
 * gcc
 * cmake
 * OpenCASCADE-devel
 * libXerces-c-devel
 * python-devel
 * libqt4-devel
 * python-qt4
 * Coin-devel
 * SoQt-devel
 * boost-devel
 * libode-devel
 * libQtWebKit-devel
 * libeigen3-devel
 * gcc-fortran
 * freetype2
 * freetype2-devel
 * Eigen3
 * swig

Also, note that the Eigen3 Library from Factory Education was causing problems sometimes, so use the one from the KDE 4.8 Extra repo

Arch Linux
You will need the following libraries from the official repositories:


 * boost-libs
 * curl
 * hicolor-icon-theme
 * libspnav
 * opencascade
 * python2-pivy
 * python2-matplotlib
 * python2-pyside
 * python2-shiboken
 * qtwebkit
 * shared-mime-info
 * xerces-c
 * boost
 * cmake
 * coin
 * desktop-file-utils
 * eigen
 * gcc-fortran
 * swig
 * xerces-c

Also, make sure to check the AUR for any missing packages that are not on the repositories, currently:
 * python2-pyside-tools

Older and non-conventional distributions
On other distributions, we have very few feedback from users, so it might be harder to find the required packages. Try first locating the required libraries mentioned in Third Party Libraries. Beware that some of them might have a slightly different package name in your distribution (such as name, libname, name-dev, name-devel, etc...).

You also need the GNU gcc compiler version equal or above 3.0.0. g++ is also 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 is also 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. Below is additional help for a couple of libraries that might not be present in your distribution repositories

Eigen 3
The Eigen3 library is now required by the Sketcher module. This library is only available starting from Ubuntu 11.10 repositories. For prior Ubuntu releases, you can either download it from here and install it manually, or add the FreeCAD Daily Builds PPA to your software sources before installing it through one of the means listed below.

OpenCASCADE community edition (OCE)
OpenCasCade has recently been forked into a Community edition, which is much, much easier to build. FreeCAD can use any version installed on your system, either the "official" edition or the community edition. The OCE website contains detailed build instructions.

OpenCASCADE official version
Note: You are advised to use the OpenCasCade community edition above, which is easier to build, but this one works too. Not all Linux distributions have an official OpenCASCADE package in their repositories. You have to check for yourself if one is available for your distribution. At least from Debian Lenny and Ubuntu Intrepid an official .deb package is provided. For older Debian or Ubuntu releases you may get unofficial packages from here. To build your own private .deb packages follow these steps:

Alternatively, you can download and compile 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:

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:

Once the package is installed, go into the "ros" directory inside the opencascade dir, and do

Now you can build. Go back to the ros folder and do:

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. Alternatively, you can also do

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

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

SoQt
The SoQt library must be compiled against Qt4, which is the case in most recent distributions. But at the time of writing this article there were only SoQt4 packages for Debian itself available but not for all Ubuntu versions. To get the packages built do the following steps:

If you are on a 64bit system, you will probably need to change i386 by amd64.

Pivy
Pivy is not needed to build FreeCAD or to run it, but it is needed for the 2D Drafting module to work. If you are not going to use that module, you won't need pivy. At the time of writing, Pivy is very new and might not have made its way into your distribution repository. If you cannot find Pivy in your distribution's packages repository, you can grab debian/ubuntu packages on the FreeCAD download page:

http://sourceforge.net/projects/free-cad/files/FreeCAD%20Linux/ or compile pivy yourself:

Pivy compilation instructions

Usando cMake
cMake è il sistema di build più recente, che ha il grande vantaggio di essere comune a differenti sistemi (Linux, Windows, MacOSX, etc). Adesso FreeCAD usa il sistema cMake come suo principale sistema. Di solito la compilazione con cMake è molto semplice e avviene in 2 fasi. Nella prima fase, CMake verifica se tutti i programmi e le librerie necessarie sono presenti nel sistema e imposta tutto ciò che è necessario per la successiva compilazione. In seguito sono proposte e descritte un paio di alternative, ma FreeCAD viene fornito con valide impostazioni predefinite. La seconda fase è la compilazione stessa, che produce l'eseguibile di FreeCAD.

Poiché FreeCAD è un'applicazione pesante, la compilazione può richiedere un po' di tempo (circa 10 minuti su una macchina veloce, 30 minuti su una lenta)

Costruzione In-source
FreeCAD può essere costruito nel sorgente (in-source), il che significa che tutti i file risultanti dalla compilazione si trovano nella stessa cartella del codice sorgente. Questo va bene per "dare un'occhiata" a FreeCAD, e permette di rimuoverlo facilmente eliminando semplicemente la sua cartella. Quando si prevede di compilarlo spesso, si consiglia invece di fare una costruzione esterna al sorgente (out-of-source) perchè offre maggiori vantaggi. I seguenti comandi compilano FreeCAD:

If you want to use your system's copy of Pivy, which you most commonly will, then set the compiler flag to use the correct pivy (via FREECAD_USE_EXTERNAL_PIVY=1) As of 0.15.xxxx this flag is set by default on Linux so it does not need to be manually set. Also, set the build type to Debug if you want a debug build or Release if not. A Release build will run much faster than a Debug build. Sketcher becomes very slow with complex sketches if your FreeCAD is a Debug build. (NOTE: the "." and space after the cmake flags are CRITICAL!):

Per una Degug build

Oppure per una Release build

L'eseguibile di FreeCAD risiede quindi nella cartella "bin", e può essere lanciato con:

Costruzione Out-of-source
Se intendete seguire la rapida evoluzione di FreeCAD, costruire in una cartella separata (Out-of-source build) è molto più conveniente. Ogni volta che il codice sorgente viene aggiornato, cMake riconosce intelligentemente i file che sono stati modificati e ricompila solo ciò che è necessario. La costruzione Out-of-source è particolarmente utile quando si utilizza il sistema Git, perché si può facilmente provare altri rami senza confondere il sistema di compilazione. Per costruire out-of-source, è sufficiente creare una cartella di generazione, distinta dalla cartella di origine FreeCAD, e, dalla cartella di compilazione, indirizzare CMake verso la cartella di origine:

The FreeCAD executable will then reside in the "bin" directory (within your freecad-build directory).

Configuration options
There are a number of experimental or unfinished modules you may have to build if you want to work on them. To do so, you need to set the proper options for the configuration phase. Do it either on the command line, passing -D : = options to cMake or using one of the availables gui-frontends (eg for Debian, packages cmake-qt-gui or cmake-curses-gui).

As an example, to configure on the command line with the Assembly module built, issue:

Possible options are listed in FreeCAD's root CmakeLists.txt file.

Qt designer plugin
If you want to develop Qt stuff for FreeCAD, you'll need the Qt Designer plugin that provides all custom widgets of FreeCAD. Go to

So far we don't provide a makefile -- but calling

creates it. Once that's done, calling

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

Doxygen
If you feel bold enough to dive in the code, you could take advantage to build and consult Doxygen generated FreeCAD's Source documentation

Making a debian package
If you plan to build a Debian package out of the sources you need to install those packages first:

To build a package open a console, simply go to the FreeCAD directory and call

Once the package is built, you can use lintian to check if the package contains errors

Note for 64bit systems
When building FreeCAD for 64-bit there is a known issue with the OpenCASCADE 64-bit package. To get FreeCAD running properly you might need to run the ./configure script with the additional define _OCC64 set:

For Debian based systems this workaround is not needed when using the prebuilt package because there the OpenCASCADE package is built to set internally this define. Now you just need to compile FreeCAD the same way as described above.

Fedora 13
To build & install FreeCAD on Fedora 13, a few tips and tricks are needed:
 * Install a bunch of required packages, most are available from the Fedora 13 repositories
 * Download and build xerces
 * Download and build OpenCascade. Need to point it to xmu:


 * Download and build Pivy. You have to remove 2 references to non existent "SoQtSpaceball.h" from pivy/interfaces/soqt.i Commenting out those two lines allow the build & install to work.
 * Configure Freecad. You will need to point it to a few things:


 * make - hits a problem where the build is breaking because the ldflags for soqt are set to "-LNONE" which made libtool barf. My hackish workaround was to modify /usr/lib/Coin2/conf/soqt-default.cfg so that the ldflags are "" instead of "-LNONE". After this -> success !

Automatic build scripts
Here is all what you need for a complete build of FreeCAD. It's a one-script-approach and works on a fresh installed distro. The commands will ask for root password (for installation of packages) and sometime to acknowledge a fingerprint for an external repository server or https-subversion repository. These scripts should run on 32 and 64 bit versions. They are written for different versions, but are also likely to run on a later version with or without major changes.

If you have such a script for your preferred distro, please send it! We will incorporate it into this article.

Ubuntu 13.x
Note that this script starts by adding the FreeCAD Daily Builds PPA repository so it can proceed with the Eigen3 library (libeigen3-dev) installation. If you already have this library installed on your system, you can remove the first line.

Ubuntu 14.x
This script prepairs your system to build freecad, and builds it for the first time. For subsiquent builds, it sufices to type make in the root freecad directory.

NOTE: When the cmake-gui window comes up, check the "use external PIVY" check-box and close it:

Note that this script starts by adding the FreeCAD Daily Builds PPA repository so it can proceed with the Eigen3 library (libeigen3-dev) installation. If you already have this library installed on your system, you can remove the first line.

OpenSUSE 12.2
No external Repositories are needed to compile FreeCAD 0.13 with this release. However, there is an imcompatability with python3-devel which needs to be removed. FreeCAD can be compiled from GIT similar to in OpenSUSE 12.2

Since you are using git, next time you wish to compile you do not have to clone everything, just pull from git and compile once more

Fedora 21
Posted by user [PrzemoF] in the forum. { echo "~/$MAIN_DIR already exist. Quitting.."; exit; }

cd $MAIN_DIR

git clone https://github.com/FreeCAD/FreeCAD_sf_master.git

mkdir $BUILD_DIR

Updating the source code
FreeCAD development happens fast, everyday or so there are bug fixes or new features. The cmake systems allows you to intelligently update the source code, and only recompile what has changed, making subsequent compilations very fast. Updating the source code with git or subversion is very easy:

Move into the appropriate build directory and run cmake again (as cmake updates the version number data for the Help menu, ...about FreeCAD), however you do not need to add the path to source code after "cmake", just a space and a dot: