Difference between revisions of "CompileOnUnix"

From FreeCAD Documentation
Jump to: navigation, search
(Marked this version for translation)
 
(266 intermediate revisions by 31 users not shown)
Line 1: Line 1:
 +
<languages/>
 
<translate>
 
<translate>
 +
<!--T:204-->
 +
{{docnav|CompileOnWindows|CompileOnMac}}
 +
 
<!--T:1-->
 
<!--T:1-->
 
On recent linux distributions, FreeCAD is generally easy to build, since all dependencies are usually provided by the package manager. It basically involves 3 steps:
 
On recent linux distributions, FreeCAD is generally easy to build, since all dependencies are usually provided by the package manager. It basically involves 3 steps:
 +
# Getting the FreeCAD source code
 +
# Getting the dependencies or packages that FreeCAD depends on
 +
# Configure with {{incode|cmake}} and compile with {{incode|make}}
 +
 +
<!--T:114-->
 +
Below, you'll find detailed explanations of the whole process, some [[#Automatic build scripts|build scripts]], and particularities you might encounter. If you find anything wrong or out of date in the text below (Linux distributions change often), or if you use a distribution which is not listed, discuss the issue in the [https://forum.freecadweb.org/index.php forum], and help us correct it.
 +
 +
<!--T:293-->
 +
[[File:FreeCAD_source_compilation_workflow.svg|800px]]
 +
 +
<!--T:294-->
 +
{{Caption|General workflow to compile FreeCAD from source. The third party dependencies must be in the system, as well as the FreeCAD source code itself. CMake configures the system so that with a single make instruction the entire project is compiled.}}
  
<!--T:2-->
+
== Getting the source == <!--T:115-->
# Getting the FreeCAD source code
 
# Getting the dependencies (packages FreeCAD depends upon)
 
# Compiling with "cmake . && make"
 
  
<!--T:3-->
+
=== Git === <!--T:116-->
Below, you'll find detailed explanations of the whole process and particularities you might encounter. If you find anything wrong or out-of-date in the text below (Linux distributions change often), or if you use a distribution which is not listed, please help us correcting it.
+
The best way to get the code is to clone the read-only [https://github.com/FreeCAD/FreeCAD Git repository]. For this you need the {{incode|git}} program which can be easily installed in most Linux distributions, and it can also be obtained from the [http://git-scm.com/ official website].
  
== Getting the source == <!--T:4-->
+
<!--T:117-->
Before you can compile FreeCAD, you need the source code. There are 3 ways to get it:
+
This will place a copy of the latest version of the FreeCAD source code in a new directory called {{incode|freecad-source}}.
  
=== Git === <!--T:5-->
 
The quickest and best way to get the code is to clone the read-only git repository (you need the [http://git-scm.com/ git] package installed):
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
{{Code|lang=bash|code=
git clone git://git.code.sf.net/p/free-cad/code free-cad-code
+
sudo apt install git
</syntaxhighlight>
+
git clone https://github.com/FreeCAD/FreeCAD.git freecad-source
 +
}}
 
<translate>
 
<translate>
<!--T:6-->
 
This will place a copy of the latest version of the FreeCAD source code in a new directory called "free-cad-code". The first time you try connecting to the free-cad.git.sourceforge.net host, you will receive a message asking to authenticate the sourceforge SSH key, which is normally safe to accept (you can check their SSH keys on the sourceforge website if you are not sure)
 
  
=== Github === <!--T:7-->
+
<!--T:298-->
There is an always up to date FreeCAD repository on Github:
+
For more information on using Git, and contributing code to the project, see [[Source code management|Source code management]].
[https://github.com/FreeCAD/FreeCAD_sf_master github.com/FreeCAD/FreeCAD_sf_master]
+
 
 +
=== Source archive === <!--T:119-->
 +
Alternatively you can download the source as an [https://github.com/FreeCAD/FreeCAD/releases/latest archive], a {{incode|.zip}} or {{incode|.tar.gz}} file, and unpack it in the desired directory.
  
=== Source package === <!--T:8-->
+
== Getting the dependencies == <!--T:121-->
Alternatively you can download a source package, but they could be already quite old so it's always better to get the latest sources via git or github. Depending on your distribution, there are several ways to obtain a source package:
+
To compile FreeCAD you have to install the requisite dependencies mentioned in [[Third Party Libraries|Third Party Libraries]]; the packages that contain these dependencies are listed below for different Linux distributions. Please note that the names and availability of the libraries will depend on your particular distribution; if your distribution is old, some packages may be unavailable of have a different name. In this case, look in the [[#Older and non-conventional distributions|older and non-conventional distributions]] section below.
  
<!--T:9-->
+
<!--T:122-->
* Official FreeCAD source packages (distribution-independent): https://sourceforge.net/projects/free-cad/files/FreeCAD%20Source/
+
Once you have all the dependencies installed proceed to [[#Compile_FreeCAD|compile FreeCAD]].
* Debian: http://packages.debian.org/source/sid/freecad
 
* Ubuntu: http://packages.ubuntu.com/source/precise/freecad
 
  
== Getting the dependencies == <!--T:10-->
+
<!--T:283-->
To compile FreeCAD under Linux you have to install all libraries mentioned in [[Third Party Libraries]] first. On recent distributions, this is generally just a matter of installing a couple of packages:
+
Please note that FreeCAD's source code is around 500 MB in size; it may be three times as big if you clone the Git repository with its entire modification history. Getting all dependencies may require downloading 500 MB or more of new files; when these files are unpacked they may require 1500 MB or more in space. Also beware that the compilation process may generate up to 1500 MB of additional files as the system copies and modifies the entire source code. Therefore, be sure you have enough free space in your hard drive, at least 4 GB, when attempting compilation.
  
=== Debian and Ubuntu === <!--T:11-->
 
On Debian-based systems (Debian, Ubuntu, Mint, etc...) it is quite easy to get all needed dependencies installed. Most of the libraries are available via apt-get or synaptic package manager. Below are listed all packgages you need to install. Note that if you don't use the most recent version of your distribution, some of the packages below might be missing from your repositories. In that case, look in the [[#Older and non-conventional distributions|Older and non-conventional distributions]] section below.
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
<div class="mw-collapsible mw-collapsed toccolours">
build-essential
 
cmake
 
python
 
python-matplotlib
 
libtool
 
either:
 
      libcoin60-dev (Debian Wheezy, Ubuntu 13.04 and before)
 
or:
 
      libcoin80-dev (Debian wheezy-backports, unstable, testing, Ubuntu 13.10 and forward, See Additional instruction below])
 
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
 
either:
 
      libopencascade-dev (official opencascade version)
 
or:
 
      liboce*-dev (opencascade community edition)
 
      oce-draw
 
gfortran
 
libeigen3-dev
 
libqtwebkit-dev
 
libshiboken-dev
 
libpyside-dev
 
libode-dev
 
swig
 
libzipios++-dev
 
libfreetype6
 
libfreetype6-dev
 
</syntaxhighlight>
 
 
<translate>
 
<translate>
<!--T:12-->
 
[http://forum.freecadweb.org/viewtopic.php?f=4&t=5096#p40018 Additional instruction] for libcoin80-dev (Debian wheezy-backports, unstable, testing, Ubuntu 13.10 and forward
 
  
<!--T:13-->
+
=== Debian and Ubuntu === <!--T:123-->
Optionally you can also install these extra packages:
+
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
<div class="mw-collapsible-content">
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)
 
</syntaxhighlight>
 
 
<translate>
 
<translate>
  
 +
<!--T:305-->
 +
On Debian-based systems (Debian, Ubuntu, Mint, etc.) it is quite easy to get all needed dependencies installed. Most of the libraries are available via {{incode|apt}} or the Synaptic package manager.
  
 +
<!--T:227-->
 +
If you already installed FreeCAD from the official repositories, you can install its build dependencies with this single line of code in a terminal:
  
=== Fedora === <!--T:14-->
 
You need the following packages:
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
{{Code|code=
cmake
+
sudo apt build-dep freecad
doxygen
+
}}
swig
 
gcc-gfortran
 
gettext
 
dos2unix
 
desktop-file-utils
 
libXmu-devel
 
freeimage-devel
 
mesa-libGLU-devel
 
OCE-devel
 
python python-devel
 
boost-devel
 
tbb-devel
 
eigen3-devel
 
qt-devel
 
qt-webkit-devel
 
ode-devel
 
xerces-c
 
xerces-c-devel
 
opencv-devel
 
smesh-devel
 
coin2-devel
 
soqt-devel
 
freetype
 
freetype-devel
 
</syntaxhighlight>
 
 
<translate>
 
<translate>
<!--T:15-->
+
 
And optionally:
+
<!--T:252-->
 +
However, if the version of FreeCAD in the repositories is old, the dependencies may be the wrong ones to compile a recent version of FreeCAD. Therefore, please verify that you have installed the following packages.
 +
 
 +
<!--T:253-->
 +
These packages are essential for any sort of compilation to succeed:
 +
*{{incode|build-essential}}, installs the C and C++ compilers, the C development libraries, and the {{incode|make}} program.
 +
*{{incode|cmake}}, essential tool to configure the source of FreeCAD. You may also wish to install {{incode|cmake-gui}} and {{incode|cmake-curses-gui}} for a graphical option.
 +
*{{incode|libtool}}, essential tools to produce shared libraries.
 +
*{{incode|lsb-release}}, the standard base reporting utility is normally already installed in a Debian system, and allows you to programmatically distinguish between a pure Debian installation or a variant, such as Ubuntu or Linux Mint. Do not remove this package, as many other system packages may depend on it.
 +
 
 +
<!--T:254-->
 +
Compilation of FreeCAD uses the Python language, and it's also used at runtime as a scripting language. If you are using a Debian based distribution the Python interpreter is normally already installed.
 +
*{{incode|python3}}
 +
*{{incode|swig}}, the tool that creates interfaces between C++ code and Python.
 +
 
 +
<!--T:284-->
 +
Please check that you have Python 3 installed. Python 2 was obsoleted in 2019, so new development in FreeCAD is not tested with this version of the language.
 +
 
 +
<!--T:255-->
 +
The Boost libraries need to be installed:
 +
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
*{{incode|libboost-dev}}
libspnav-devel (for 3Dconnexion devices support like the Space Navigator or Space Pilot)
+
*{{incode|libboost-date-time-dev}}
pivy ( https://bugzilla.redhat.com/show_bug.cgi?id=458975 Pivy is not mandatory but needed for the Draft module )
+
*{{incode|libboost-filesystem-dev}}
</syntaxhighlight>
+
*{{incode|libboost-graph-dev}}
 +
*{{incode|libboost-iostreams-dev}}
 +
*{{incode|libboost-program-options-dev}}
 +
*{{incode|libboost-python-dev}}
 +
*{{incode|libboost-regex-dev}}
 +
*{{incode|libboost-serialization-dev}}
 +
*{{incode|libboost-signals-dev}}
 +
*{{incode|libboost-thread-dev}}
 
<translate>
 
<translate>
<!--T:16-->
 
Building FreeCAD with coin3 is still more hassle on Fedora, since only coin2 is provided in the official repos, but if you wish so anyway, you can avoid to rebuild all the coin3 / soqt / pivy suite by installing coin3-ready packages from http://www.zultron.com/rpm-repo/
 
  
==== Fedora 20 ====
+
<!--T:228-->
Install the "free" and "nonfree" Fedora repositories:
+
The Coin libraries need to be installed:
 +
*{{incode|libcoin80-dev}}, for Debian Jessie, Stretch, Ubuntu 16.04 to 18.10, or
 +
*{{incode|libcoin-dev}}, for Debian Buster, Ubuntu 19.04 and newer, as well as for Ubuntu 18.04/18.10 with the [[Install_on_Unix#Official_Ubuntu_repository|freecad-stable/freecad-daily PPAs]] added to your software sources.
  
<code><nowiki>
+
<!--T:257-->
$ su -c 'yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm'
+
Several libraries that deal with mathematics, triangulated surfaces, sorting, meshes, computer vision, cartographic projections, 3D visualization, the X11 Window system, XML parsing, and Zip file reading:
</nowiki></code>
 
  
Now, install the required packages:
+
</translate>
 +
*{{incode|libeigen3-dev}}
 +
*{{incode|libgts-bin}}
 +
*{{incode|libgts-dev}}
 +
*{{incode|libkdtree++-dev}}
 +
*{{incode|libmedc-dev}}
 +
*{{incode|libopencv-dev}} or {{incode|libcv-dev}}
 +
*{{incode|libproj-dev}}
 +
*{{incode|libvtk7-dev}} or {{incode|libvtk6-dev}}
 +
*{{incode|libx11-dev}}
 +
*{{incode|libxerces-c-dev}}
 +
*{{incode|libzipios++-dev}}
  
<code><nowiki>
+
<div class="mw-collapsible mw-collapsed" style="background-color:#e0e0e0">
$ sudo yum install cmake doxygen swig gcc-gfortran gettext dos2unix desktop-file-utils libXmu-devel freeimage-devel mesa-libGLU-devel OCE-devel python python-devel boost-devel tbb-devel eigen3-devel qt-devel qt-webkit-devel ode-devel xerces-c xerces-c-devel opencv-devel smesh-devel freetype freetype-devel gcc-c++ git libspnav-devel shiboken-devel python-pyside-devel python-matplotlib wget mercurial Coin2-devel
+
<translate>
</nowiki></code>
 
  
Create a symbolic link so that cmake will find the Coin/Inventor files:
+
==== Python 2 and Qt4 ==== <!--T:258-->
 +
This is not recommended for newer installations as both Python 2 and Qt4 are obsolete.
  
<code><nowiki>
+
</translate>
$ sudo ln -s /usr/include/Coin2/Inventor /usr/include/Inventor
+
<div class="mw-collapsible-content">
</nowiki></code>
+
<translate>
  
Download the tarball for SoQt-1.5.0-10:
+
<!--T:306-->
 +
To compile FreeCAD for Debian Jessie, Stretch, Ubuntu 16.04, using Python 2 and Qt4, install the following dependencies.
  
<code><nowiki>
+
</translate>
$ cd ~/Downloads/
+
*{{incode|qt4-dev-tools}}
$ wget http://pkgs.fedoraproject.org/repo/pkgs/SoQt/SoQt-1.5.0.tar.gz/9f1e582373d66f556b1db113a93ac68e/SoQt-1.5.0.tar.gz
+
*{{incode|libqt4-dev}}
$ tar -xvf SoQt-1.5.0.tar.gz
+
*{{incode|libqt4-opengl-dev}}
</nowiki></code>
+
*{{incode|libqtwebkit-dev}}
 +
*{{incode|libshiboken-dev}}
 +
*{{incode|libpyside-dev}}
 +
*{{incode|pyside-tools}}
 +
*{{incode|python-dev}}
 +
*{{incode|python-matplotlib}}
 +
*{{incode|python-pivy}}
 +
*{{incode|python-ply}}
 +
*{{incode|python-pyside}}
  
Compile SoQt:
+
</div>
 +
</div>
 +
<translate>
  
<code><nowiki>
+
==== Python 3 and Qt5 ==== <!--T:259-->
$ cd SoQt-1.5.0/
 
$ ./configure
 
$ make
 
$ sudo make install
 
</nowiki></code>
 
  
Download, build and install pivy:
+
<!--T:232-->
 +
To compile FreeCAD for Debian Buster, Ubuntu 19.04 and newer, as well as Ubuntu 18.04/18.10 with the [[Install_on_Unix#Official_Ubuntu_repository|freecad-stable/freecad-daily PPAs]] added to your software sources, install the following dependencies.
  
<code><nowiki>
+
</translate>
$ cd ~/Downloads/
+
*{{incode|qtbase5-dev}}
$ hg clone https://bitbucket.org/Coin3D/pivy pivy-code
+
*{{incode|qttools5-dev}}
$ cd pivy-code
+
*{{incode|libqt5opengl5-dev}}
$ python setup.py build
+
*{{incode|libqt5svg5-dev}}
$ sudo python setup.py install
+
*{{incode|libqt5webkit5-dev}} or {{incode|qtwebengine5-dev}}
</nowiki></code>
+
*{{incode|libqt5xmlpatterns5-dev}}
 +
*{{incode|libqt5x11extras5-dev}}
 +
*{{incode|libpyside2-dev}}
 +
*{{incode|libshiboken2-dev}}
 +
*{{incode|pyside2-tools}}
 +
*{{incode|python3-dev}}
 +
*{{incode|python3-matplotlib}}
 +
*{{incode|python3-pivy}}
 +
*{{incode|python3-ply}}
 +
*{{incode|python3-pyside2.qtcore}}
 +
*{{incode|python3-pyside2.qtgui}}
 +
*{{incode|python3-pyside2.qtsvg}}
 +
*{{incode|python3-pyside2.qtwidgets}}
 +
*{{incode|python3-pyside2uic}}
 +
<translate>
 +
 
 +
==== OpenCascade kernel ==== <!--T:233-->
 +
 
 +
<!--T:260-->
 +
The OpenCascade kernel is the core graphics library to create 3D shapes. It exists in an official version OCCT, and a community version OCE. The community version is no longer recommended, as it's outdated.
  
[[CompileOnUnix#In-souce_building|Skip to Compile FreeCAD]]
+
<!--T:261-->
 +
For Debian Buster and Ubuntu 18.10 and newer, as well as Ubuntu 18.04 with the [[Install_on_Unix#Official_Ubuntu_repository|freecad-stable/freecad-daily PPAs]] added to your software sources, install the official packages.
  
=== Gentoo === <!--T:17-->
 
You need the following packages to build FreeCAD:
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
*{{incode|libocct*-dev}}
dev-cpp/eigen
+
**{{incode|libocct-data-exchange-dev}}
dev-games/ode
+
**{{incode|libocct-draw-dev}}
dev-libs/boost
+
**{{incode|libocct-foundation-dev}}
dev-libs/xerces-c
+
**{{incode|libocct-modeling-algorithms-dev}}
dev-python/pivy
+
**{{incode|libocct-modeling-data-dev}}
dev-python/PyQt4
+
**{{incode|libocct-ocaf-dev}}
media-libs/coin
+
**{{incode|libocct-visualization-dev}}
media-libs/SoQt
+
*{{incode|occt-draw}}
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
 
</syntaxhighlight>
 
 
<translate>
 
<translate>
<!--T:18-->
+
 
Since latest opencascade is not available, you might want to compile opencascade too, hence the following additional libaries are needed:
+
<!--T:262-->
 +
For Debian Jessie, Stretch, Ubuntu 16.04 and newer, install the community edition packages.
 +
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
*{{incode|liboce*-dev}}
media-libs/ftgl
+
**{{incode|liboce-foundation-dev}}
virtual/opengl
+
**{{incode|liboce-modeling-dev}}
x11-libs/libXmu
+
**{{incode|liboce-ocaf-dev}}
dev-lang/tcl-8.5.9
+
**{{incode|liboce-ocaf-lite-dev}}
dev-lang/tk-8.5.9-r1
+
**{{incode|liboce-visualization-dev}}
dev-tcltk/itcl-3.4_beta1
+
*{{incode|oce-draw}}
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
 
</syntaxhighlight>
 
 
<translate>
 
<translate>
  
 +
<!--T:125-->
 +
You may install the libraries individually, or using asterisk expansion. Change {{incode|occ}} for {{incode|oce}} if you want to install the community libraries.
  
=== OpenSUSE === <!--T:19-->
 
You need the following packages:
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
{{Code|code=
gcc
+
sudo apt install libocct*-dev
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
 
</syntaxhighlight>
 
 
<translate>
 
<translate>
<!--T:20-->
+
 
For FreeCAD 0.13 unstable you need to add Eigen3 and swig libraries, that don't seem to be in standard repos. You can get them with one-click install here:
+
==== Optional packages ==== <!--T:127-->
 +
Optionally you can also install these extra packages:
 +
* {{incode|libsimage-dev}}, to make Coin support additional image file formats.
 +
* {{incode|doxygen}} and {{incode|libcoin-doc}} (or {{incode|libcoin80-doc}} for older systems), if you intend to generate source code documentation.
 +
* {{incode|libspnav-dev}}, for [[3D input devices|3D input devices]] support, like the 3Dconnexion "Space Navigator" or "Space Pilot".
 +
* {{incode|checkinstall}}, if you intend to register your installed files into your system's package manager, so you can uninstall it later.
 +
 
 +
==== Single command for Python 3 and Qt5 ==== <!--T:238-->
 +
Requires Pyside2 available in Debian buster and the [[Install_on_Unix#Official_Ubuntu_repository|freecad-stable/freecad-daily PPAs]].
 +
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
{{Code|code=
Eigen3: http://software.opensuse.org/search?q=eigen3&baseproject=openSUSE%3A12.1&lang=en&exclude_debug=true
+
sudo apt install cmake cmake-gui libboost-date-time-dev libboost-dev libboost-filesystem-dev libboost-graph-dev libboost-iostreams-dev libboost-program-options-dev libboost-python-dev libboost-regex-dev libboost-serialization-dev libboost-signals-dev libboost-thread-dev libcoin-dev libeigen3-dev libgts-bin libgts-dev libkdtree++-dev libmedc-dev libocct-data-exchange-dev libocct-ocaf-dev libocct-visualization-dev libopencv-dev libproj-dev libpyside2-dev libqt5opengl5-dev libqt5svg5-dev libqt5webkit5-dev libqt5x11extras5-dev libqt5xmlpatterns5-dev libshiboken2-dev libspnav-dev libvtk7-dev libx11-dev libxerces-c-dev libzipios++-dev occt-draw pyside2-tools python3-dev python3-matplotlib python3-pivy python3-ply python3-pyside2.qtcore python3-pyside2.qtgui python3-pyside2.qtsvg python3-pyside2.qtwidgets python3-pyside2uic qtbase5-dev qttools5-dev swig
swig: http://software.opensuse.org/search?q=swig&baseproject=openSUSE%3A12.1&lang=en&exclude_debug=true
+
}}
</syntaxhighlight>
+
 
 +
<div class="mw-collapsible mw-collapsed" style="background-color:#e0e0e0">
 
<translate>
 
<translate>
<!--T:21-->
 
Also, note that Eigen3 Library from Factory Education was causing problems sometimes, so use the one from KDE 4.8 Extra repo
 
  
=== Older and non-conventional distributions === <!--T:22-->
+
==== Single command for Python 2 and Qt4 ==== <!--T:239-->
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...).
+
This is not recommended for newer installations as both Python 2 and Qt4 are obsolete.
  
<!--T:23-->
+
</translate>
You also need the [[wikipedia:GNU Compiler Collection|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.
+
<div class="mw-collapsible-content">
  
<!--T:24-->
+
{{Code|code=
For more details have also a look to ''README.Linux'' in your sources.
+
sudo apt install cmake debhelper dh-exec dh-python libboost-date-time-dev libboost-dev libboost-filesystem-dev libboost-graph-dev libboost-iostreams-dev libboost-program-options-dev libboost-python-dev libboost-regex-dev libboost-serialization-dev libboost-signals-dev libboost-thread-dev libcoin80-dev libeigen3-dev libgts-bin libgts-dev libkdtree++-dev libmedc-dev libocct-data-exchange-dev libocct-ocaf-dev libocct-visualization-dev libopencv-dev libproj-dev libpyside-dev libqt4-dev libqt4-opengl-dev libqtwebkit-dev libshiboken-dev libspnav-dev libvtk6-dev libx11-dev libxerces-c-dev libzipios++-dev lsb-release occt-draw pyside-tools python-dev python-matplotlib python-pivy python-ply swig
 +
}}
  
<!--T:25-->
+
<translate>
Below is additional help for a couple of libraries that might not be present in your distribution repositories
+
<!--T:128-->
 +
Ubuntu 16.04 users please see also the compilation discussion in the forum: [http://forum.freecadweb.org/viewtopic.php?f=4&t=16292 Compile on Linux (Kubuntu): CMake can't find VTK].
  
==== Eigen 3 ==== <!--T:26-->
+
</translate>
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 [http://packages.ubuntu.com/oneiric/libeigen3-dev from here] and install it manually, or add the [https://launchpad.net/~freecad-maintainers/+archive/freecad-daily FreeCAD Daily Builds PPA] to your software sources before installing it through one of the means listed below.
+
</div>
 +
</div>
 +
</div>
 +
</div>
  
==== OpenCASCADE community edition (OCE) ==== <!--T:27-->
+
<div class="mw-collapsible mw-collapsed toccolours">
OpenCasCade has recently been forked into a [http://github.com/tpaviot/oce 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.
+
<translate>
  
==== OpenCASCADE official version ==== <!--T:28-->
+
=== Fedora === <!--T:157-->
'''Note''': You are advised to use the OpenCasCade community edition above, which is easier to build, but this one works too.
 
  
<!--T:29-->
 
Not all Linux distributions have an official OpenCASCADE package in their repositories. You have to check yourself for your distribution if one is available. At least from Debian Lenny and Ubuntu Intrepid on an official .deb package is provided. For older Debian or Ubuntu releases you may get unofficial packages from [http://lyre.mit.edu/~powell/opencascade here]. To build your own private .deb packages follow these steps:
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
<div class="mw-collapsible-content">
wget http://lyre.mit.edu/~powell/opencascade/opencascade_6.2.0.orig.tar.gz
+
<translate>
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
+
<!--T:174-->
 +
You need the following packages :
  
# Install OCC build-deps
+
</translate>
sudo apt-get install build-essential devscripts debhelper autoconf
+
<!--<div style="column-count:2;-moz-column-count:2;-webkit-column-count:2">-->
automake libtool bison libx11-dev tcl8.4-dev tk8.4-dev libgl1-mesa-dev
+
*gcc-c++ (or possibly another C++ compiler?)
libglu1-mesa-dev java-gcj-compat-dev libxmu-dev
+
*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
 +
<translate>
  
#Build Opencascade packages. This takes hours and requires
+
<!--T:175-->
# at least 8 GB of free disk space
+
(if coin2 is the latest available for your version of Fedora, use packages from http://www.zultron.com/rpm-repo/)
cd opencascade-6.2.0 ; debuild
 
  
# Install the resulting library debs
+
</translate>
sudo dpkg -i libopencascade6.2-0_6.2.0-7_i386.deb
+
*soqt-devel
libopencascade6.2-dev_6.2.0-7_i386.deb
+
*freetype
</syntaxhighlight>
+
*freetype-devel
 +
<!--</div>-->
 
<translate>
 
<translate>
<!--T:30-->
 
Alternatively, you can download and compile the latest version from [http://www.opencascade.org opencascade.org]:
 
  
<!--T:31-->
+
<!--T:176-->
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:
+
And optionally :  
 +
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
<!--<div style="column-count:2;-moz-column-count:2;-webkit-column-count:2">-->
sudo apt-get remove gij
 
sudo apt-get install sun-java6-jre
 
</syntaxhighlight>
 
 
<translate>
 
<translate>
<!--T:32-->
+
 
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:
+
<!--T:177-->
 +
*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)
 +
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
</div>
java -cp path_to_file_setup.jar <-Dtemp.dir=path_to_tmp_directory> run
+
</div>
</syntaxhighlight>
+
<div class="mw-collapsible mw-collapsed toccolours">
 
<translate>
 
<translate>
<!--T:33-->
+
 
Once the package is installed, go into the "ros" directory inside the opencascade dir, and do
+
=== Gentoo === <!--T:132-->
 +
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
<div class="mw-collapsible-content">
./configure --with-tcl=/usr/lib/tcl8.4 --with-tk=/usr/lib/tk8.4
 
</syntaxhighlight>
 
 
<translate>
 
<translate>
<!--T:34-->
+
 
Now you can build. Go back to the ros folder and do:
+
<!--T:307-->
 +
Easiest way to check which packages are needed to compile FreeCAD is to check via portage:
 +
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
<tt>emerge -pv freecad</tt>
make
 
</syntaxhighlight>
 
 
<translate>
 
<translate>
<!--T:35-->
 
It will take a long time, maybe several hours.
 
  
<!--T:36-->
+
<!--T:161-->
When it is done, just install by doing
+
This should give a nice list of extra packages that you need installed on your system.
 +
 
 +
<!--T:196-->
 +
If FreeCAD is not available on portage, it is available on the [https://github.com/waebbl/waebbl-gentoo waebbl overlay]. The issue tracker on the waebbl overlay Github may help guide through some issues you may come across. The overlay provides <tt>freecad-9999</tt>, which you can choose to compile, or simply use to get the dependencies.
 +
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
<tt>layman -a waebbl</tt>
sudo make install
+
 
</syntaxhighlight>
+
</div>
 +
</div>
 +
<div class="mw-collapsible mw-collapsed toccolours">
 
<translate>
 
<translate>
<!--T:37-->
+
 
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
+
=== openSUSE === <!--T:308-->
 +
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
<div class="mw-collapsible-content">
sudo checkinstall
 
</syntaxhighlight>
 
 
<translate>
 
<translate>
<!--T:38-->
+
 
which will do the same as make install but create an entry in your package management system so you can easily uninstall later.
+
==== Tumbleweed ==== <!--T:309-->
Now clean up the enormous temporary compilation files by doing
+
 
 +
<!--T:240-->
 +
The following commands will install the packages required for building FreeCAD with Qt5 and Python 3.
 +
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
{{Code|code=
make clean
+
zypper in --no-recommends -t pattern devel_C_C++ devel_qt5
</syntaxhighlight>
+
 
 +
zypper in libqt5-qtbase-devel libqt5-qtsvg-devel libqt5-qttools-devel boost-devel swig libboost_program_options-devel libboost_mpi_python3-devel libboost_system-devel libboost_program_options-devel libboost_regex-devel libboost_python3-devel libboost_thread-devel libboost_system-devel libboost_headers-devel libboost_graph-devel python3 python3-devel python3-matplotlib python3-matplotlib-qt5 python3-pyside2 python3-pyside2-devel python3-pivy gcc gcc-fortran cmake occt-devel libXi-devel opencv-devel libxerces-c-devel Coin-devel SoQt-devel freetype2-devel eigen3-devel libode6 vtk-devel libmed-devel hdf5-openmpi-devel openmpi2-devel netgen-devel freeglut-devel libspnav-devel f2c doxygen dos2unix glew-devel
 +
}}
 +
 
 
<translate>
 
<translate>
<!--T:39-->
+
<!--T:241-->
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.
+
The following command will install Qt Creator and the GNU Project Debugger.
 +
</translate>
  
<!--T:40-->
+
{{Code|code=zypper in libqt5-creator gdb}}
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
+
 
 +
<translate>
 +
<!--T:242-->
 +
If any packages are missing, then you can check the Tumbleweed [https://build.opensuse.org/package/view_file/openSUSE:Factory/FreeCAD/FreeCAD.spec "FreeCAD.spec"] file on the [https://build.opensuse.org/package/show/openSUSE:Factory/FreeCAD Open Build Service].
 +
 
 +
<!--T:243-->
 +
Also, check to see if there are any patches you need to apply (such as [https://build.opensuse.org/package/view_file/openSUSE:Factory/FreeCAD/0001-find-openmpi2-include-files.patch 0001-find-openmpi2-include-files.patch]).
 +
 
 +
==== Leap ==== <!--T:310-->
 +
 
 +
<!--T:244-->
 +
If there is a difference between the available packages on Tumbleweed and Leap, then you can read the Leap [https://build.opensuse.org/package/view_file/openSUSE:Leap:15.0/FreeCAD/FreeCAD.spec "FreeCAD.spec"] file on the [https://build.opensuse.org/ Open Build Service] to determine the required packages.
 +
 
 +
</translate>
 +
</div>
 +
</div>
 +
<div class="mw-collapsible mw-collapsed toccolours">
 +
<translate>
 +
 
 +
=== Arch Linux === <!--T:311-->
 +
 
 +
</translate>
 +
<div class="mw-collapsible-content">
 +
<translate>
 +
 
 +
<!--T:245-->
 +
You will need the following libraries from the official repositories:
 +
</translate>
 +
<!--<div style="column-count:2;-moz-column-count:2;-webkit-column-count:2">-->
 +
*boost-libs
 +
*curl
 +
*desktop-file-utils
 +
*glew
 +
*hicolor-icon-theme
 +
*jsoncpp
 +
*libspnav
 +
*med
 +
*opencascade
 +
*shiboken2
 +
*xerces-c
 +
*pyside2
 +
*python-matplotlib
 +
*python-netcdf4
 +
*qt5-svg
 +
*qt5-webkit
 +
*qt5-webengine
 +
*boost
 +
*cmake
 +
*eigen
 +
*git
 +
*gcc-fortran
 +
*pyside2-tools
 +
*swig
 +
*qt5-tools
 +
*shared-mime-info
 +
<!--</div>-->
 +
<translate>
 +
 
 +
<!--T:138-->
 +
Also, make sure to check the AUR for any missing packages that are not on the repositories, currently:
 +
 
 +
</translate>
 +
*coin
 +
*python-pivy
 +
*med
 +
 
 +
{{Code|code=
 +
sudo pacman -S boost-libs curl desktop-file-utils glew hicolor-icon-theme jsoncpp libspnav med opencascade shiboken2 xerces-c pyside2 python-matplotlib python-netcdf4 qt5-svg qt5-webkit qt5-webengine cmake eigen git gcc-fortran pyside2-tools swig qt5-tools shared-mime-info coin python-pivy med
 +
}}
 +
<!--T:139-->
 +
</div>
 +
</div>
 +
 
 +
<div class="mw-collapsible mw-collapsed toccolours">
 +
<translate>
 +
 
 +
=== Older and non-conventional distributions === <!--T:140-->
  
==== SoQt ==== <!--T:41-->
 
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:
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
<div class="mw-collapsible-content">
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-6.dsc
 
wget http://ftp.de.debian.org/debian/pool/main/s/soqt/soqt_1.4.1-6.diff.gz
 
dpkg-source -x soqt_1.4.1-6.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-6_i386.deb libsoqt4-dev_1.4.1-6_i386.deb libsoqt-dev-common_1.4.1-6_i386.deb
 
</syntaxhighlight>
 
 
<translate>
 
<translate>
<!--T:42-->
 
If you are on a 64bit system, you will probably need to change i386 by amd64.
 
  
==== Pivy ==== <!--T:43-->
+
<!--T:312-->
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:
+
On other distributions, we have very few feedback from users, so it might be harder to find the required packages.
  
<!--T:44-->
+
<!--T:290-->
http://sourceforge.net/projects/free-cad/files/FreeCAD%20Linux/
+
Try first locating the required libraries mentioned in [[Third Party Libraries|third party libraries]] in your package manager. Beware that some of them might have a slightly different package name; search for {{incode|name}}, but also {{incode|libname}}, {{incode|name-dev}}, {{incode|name-devel}}, and similar. If that is not possible try compiling those libraries yourself.
  
<!--T:45-->
+
<!--T:141-->
or compile pivy yourself:
+
FreeCAD requires the GNU g++ compiler version equal or above 3.0.0, as FreeCAD is mostly written in C++. During the compilation some Python scripts are executed, so the Python interpreter has to work properly. To avoid any linker problems it is also a good idea to have the library paths in the {{incode|LD_LIBRARY_PATH}} variable or in the {{incode|ld.so.conf}} file. This is already done in modern Linux distributions, but may need to be set in older ones.
  
<!--T:46-->
+
</translate>
[[Extra_python_modules#Pivy|Pivy compilation instructions]]
+
</div>
 +
</div>
 +
<translate>
 +
 
 +
=== Pivy === <!--T:43-->
 +
 
 +
<!--T:299-->
 +
[[Pivy|Pivy]] (Python wrappers to Coin3d) is not needed to build FreeCAD or to start it, but it is needed as a runtime dependency by the [[Draft Module|Draft Workbench]]. If you are not going to use this workbench, you won't need Pivy. However, do notice that the Draft Workbench is used internally by other workbenches, like [[Arch Workbench|Arch]] and [[BIM Workbench|BIM]], so Pivy needs to be installed to use these workbenches as well.
 +
 
 +
<!--T:287-->
 +
By November 2015 the obsolete version of Pivy included with the FreeCAD source code will no longer compile on many systems. This isn't a big problem as normally you should get Pivy from your distribution's package manager; if you cannot find Pivy, you may have to compile it yourself, see [[Extra_python_modules#Pivy|Pivy compilation instructions]].
 +
 
 +
=== Debug symbols === <!--T:300-->
 +
 
 +
<!--T:301-->
 +
In order to troubleshoot crashes in FreeCAD, it is useful to have the debug symbols of important dependency libraries such as Qt. For this, try installing the dependency packages that end with {{incode|-dbg}}, {{incode|-dbgsym}}, {{incode|-debuginfo}} or similar, depending on your Linux distribution.
 +
 
 +
<!--T:302-->
 +
For Ubuntu, you may have to enable especial repositories to be able to see and install these debug packages with the package manager. See [https://wiki.ubuntu.com/Debug_Symbol_Packages Debug Symbol Packages] for more information.
  
 
== Compile FreeCAD == <!--T:47-->
 
== Compile FreeCAD == <!--T:47-->
  
=== Using cMake === <!--T:48-->
+
<!--T:207-->
cMake is a newer build system which has the big advantage of being common for different target systems (Linux, Windows, MacOSX, etc). FreeCAD is now using the cMake system as its main building system. Compiling with cMake is usually very simple and happens in 2 steps. In the first step, cMake checks that every needed programs and libraries are present on your system and sets up all that's necessary for the subsequent compilation. You are given a few alternatives detailed below, but FreeCAD comes with sensible defaults. The second step is the compiling itself, which produces the FreeCAD executable.
+
FreeCAD uses CMake as its main build system, as it's available on all major operating systems. Compiling with CMake is usually very simple and happens in two steps.
 +
 
 +
<!--T:208-->
 +
# CMake checks that every needed program and library is present on your system, and generates a {{incode|Makefile}} that is configured for the second step. FreeCAD has several configuration options to choose from, but it comes with sensible defaults. Some alternatives are detailed below.
 +
# The compilation itself, which is done with the program {{incode|make}}, which generates the FreeCAD executables.
  
 
<!--T:49-->
 
<!--T:49-->
Since FreeCAD is a heavy application, compiling can take a bit of time (about 10 minutes on a fast machine, 30 minutes on a slow one)
+
Since FreeCAD is a large application, compiling the entire source code can take anywhere from 10 minutes to one hour, depending on your CPU and the number of CPU cores used for compilation.
 +
 
 +
<!--T:251-->
 +
You can build the code either in or out of the source directory. Out-of-source building is generally the best option.
 +
 
 +
=== Out-of-source build === <!--T:52-->
 +
Building in a separate folder is more convenient than building in the same directory where the source code is located as every time you update the source code CMake can intelligently determine which files have changed, and recompile only what is needed. This is very useful when testing different Git branches as you don't confuse the build system.
 +
 
 +
<!--T:288-->
 +
To build out-of-source, simply create a build directory, {{incode|freecad-build}}, distinct from your FreeCAD source folder, {{incode|freecad-source}}; then from this build directory point {{incode|cmake}} to the right source folder. You can use {{incode|cmake-gui}} or {{incode|ccmake}} instead of {{incode|cmake}} in the instructions below as well. Once {{incode|cmake}} finishes configuring the environment, use {{incode|make}} to start the actual compilation.
 +
 
 +
</translate>
 +
{{Code|lang=bash|code=
 +
mkdir freecad-build
 +
cd freecad-build
 +
cmake ../freecad-source
 +
make -j$(nproc --ignore=2)
 +
}}
 +
<translate>
 +
 
 +
<!--T:209-->
 +
The {{incode|-j}} option of {{incode|make}} controls how many jobs (files) are compiled in parallel. The {{incode|nproc}} program prints the number of CPU cores in your system; by using it together with the {{incode|-j}} option you can choose to process as many files as you have cores, in order to speed up overall compilation of the program. In the example above, it will use all cores in your system except two; this will keep your computer responsive for other uses while compilation proceeds in the background. The FreeCAD executable will eventually appear in the {{incode|freecad-build/bin}} directory. See also [[Compiling_(Speeding_up)|Compiling (speeding up)]] to improve compilation speed.
 +
 
 +
=== In-source building === <!--T:50-->
 +
 
 +
<!--T:210-->
 +
In-source builds are fine if you want to compile a version of FreeCAD quickly, and don't intend to update the source code often. In this case, you can remove the compiled program and the source just by deleting a single folder.
 +
 
 +
<!--T:211-->
 +
Change to the source directory, and point {{incode|cmake}} to the present directory (denoted by a single point):
 +
 
 +
</translate>
 +
{{Code|lang=bash|code=
 +
cd freecad-source
 +
cmake .
 +
make -j$(nproc --ignore=2)
 +
}}
 +
<translate>
 +
 
 +
<!--T:212-->
 +
The FreeCAD executable will then reside in the {{incode|freecad-source/bin}} directory.
 +
 
 +
=== How to repair your source code directory === <!--T:162-->
 +
 
 +
<!--T:263-->
 +
If you accidentally performed a compilation inside the source code directory, or added strange files, and would like to restore the contents to only the original source code, you can perform the following steps.
 +
 
 +
</translate>
 +
{{Code|lang=bash|code=
 +
> .gitignore
 +
git clean -df
 +
git reset --hard HEAD
 +
}}
 +
<translate>
  
==== In-souce building ==== <!--T:50-->
+
<!--T:198-->
FreeCAD can be built in-source, which means that all the files resulting from the compilation stay in the same folder as the source code. This is fine if you are just looking at FreeCAD, and want to be able to remove it easily by just deleting that folder. But in case you are planning to compile it often, you are advised to make an out-of-source build, which offers many more advantages. The following commands will compile freecad:
+
The first line clears the {{incode|.gitignore}} file. This ensures that the following clean and reset commands will affect everything in the directory and will not ignore items matching the expressions in {{incode|.gitignore}}. The second line deletes all files and directories that are not tracked by the git repository; then the last command will reset any changes to tracked files, including the first command which cleared the {{incode|.gitignore}} file.
  
<code><nowiki>
+
<!--T:264-->
$ cd freecad (the folder where you cloned the freecad source)
+
If you do not clear the source directory, subsequent runs of {{incode|cmake}} may not capture new options to the system if the code changes.
</nowiki></code>
 
  
If you installed pivy from source, set the compiler flag to use the correct pivy (via FREECAD_USE_EXTERNAL_PIVY=1). Also, set the build type to debug. (NOTE: the "." and space after the cmake flags are CRITICAL!):
+
=== Configuration === <!--T:213-->
<code><nowiki>
 
$ cmake -DFREECAD_USE_EXTERNAL_PIVY=1 -DCMAKE_BUILD_TYPE=Debug .
 
$ make
 
</nowiki></code>
 
  
<!--T:51-->
+
<!--T:214-->
Your FreeCAD executable will then reside in the "bin" folder, and you can launch it with:
+
By passing different options to {{incode|cmake}}, you can change how FreeCAD is compiled. The syntax is as follows.
<code><nowiki>
 
$ ./bin/FreeCAD
 
</nowiki></code>
 
  
==== Out-of-source build ==== <!--T:52-->
 
If you intend to follow the fast evolution of FreeCAD, building in a separate folder is much more convenient. Everytime you update the source code, cMake will then intelligently distinguish which files have changed, and recompile only what is needed. Out-of-source builds are specially handy when using the Git system, because you can easily try other branches without confusing the build system. To build out-of-source, simply create a build directory, distinct from your freecad source folder, and, from the build folder, point cMake to the source folder:
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
{{Code|code=
mkdir freecad-build
+
cmake -D <var>:<type>=<value> $SOURCE_DIR
cd freecad-build
+
}}
cmake ../freecad (or whatever the path is to your FreeCAD source folder)
 
make
 
</syntaxhighlight>
 
 
<translate>
 
<translate>
<!--T:53-->
 
The FreeCAD executable will then reside in the "bin" directory (within your freecad-build directory).
 
  
==== Configuration options ==== <!--T:54-->
+
<!--T:265-->
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 <nowiki>-D <var>:<type>=<value></nowiki> options to cMake or using one of the availables gui-frontends (eg for Debian, packages cmake-qt-gui or cmake-curses-gui).
+
Where {{incode|$SOURCE_DIR}} is the directory that contains the source code. The {{incode|<type>}} may be omitted in most cases. The space after the {{incode|-D}} option may also be omitted.
 +
 
 +
<!--T:266-->
 +
For example, to avoid building the [[FEM Workbench|FEM Workbench]]:
  
<!--T:55-->
 
As an example, to configure on the command line with the Assembly module built, issue:
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
{{Code|lang=bash|code=
cmake -D FREECAD_BUILD_ASSEMBLY:BOOL=ON ''path-to-freecad-root''
+
cmake -D BUILD_FEM:BOOL=OFF ../freecad-source
</syntaxhighlight>
+
cmake -DBUILD_FEM=OFF ../freecad-source
 +
}}
 
<translate>
 
<translate>
<!--T:56-->
 
Possible options are listed in FreeCAD's root CmakeLists.txt file. 
 
  
=== Using autotools === <!--T:57-->
+
<!--T:215-->
Autotools is in the process of being deprecated in favor of cMake, but at the moment it is still available to build FreeCAD. You must have automake and libtool installed on your system; on Debian/Ubuntu:
+
All possible variables are listed in the {{incode|CMakeLists.txt}} file, located in the toplevel {{incode|freecad-source}} directory. In this file, search for the word {{incode|option}} to get to the variables that can be set, and see their default values.
 +
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
<!--NOT CHANGE THE <pre> </pre> BALISE-->
aptitude install automake libtool
+
<pre>
</syntaxhighlight>
 
 
<translate>
 
<translate>
<!--T:58-->
+
 
If you got the sources with git or subversion, then the very first step must be
+
<!--T:313-->
 +
# ==============================================================================
 +
# =================  All the options for the build process    =================
 +
# ==============================================================================
 +
 
 +
<!--T:314-->
 +
option(BUILD_FORCE_DIRECTORY "The build directory must be different to the source directory." OFF)
 +
option(BUILD_GUI "Build FreeCAD Gui. Otherwise you have only the command line and the Python import module." ON)
 +
option(FREECAD_USE_EXTERNAL_ZIPIOS "Use system installed zipios++ instead of the bundled." OFF)
 +
option(FREECAD_USE_EXTERNAL_SMESH "Use system installed smesh instead of the bundled." OFF)
 +
...
 
</translate>
 
</translate>
<syntaxhighlight>
+
</pre>
./autogen.sh
+
<!--NOT CHANGE THE <pre> </pre> BALISE-->
</syntaxhighlight>
 
 
<translate>
 
<translate>
<!--T:59-->
+
 
that creates the configure script and more. For the build process itself we provide a configure script. Just type
+
<!--T:268-->
 +
Alternatively, use the command {{incode|cmake -LH}} to list the current configuration, and thus all variables that can be changed. You may also install and use {{incode|cmake-gui}} to launch a graphical interface showing all the variables that can be modified. In the next sections we list some of the more relevant options that you may want to use.
 +
 
 +
==== For a Debug build ==== <!--T:155-->
 +
 
 +
<!--T:269-->
 +
Create a {{incode|Debug}} build to troubleshoot crashes in FreeCAD. Beware that with this build the [[Sketcher Workbench|Sketcher]] becomes very slow with complex sketches.
 +
 
 +
</translate>
 +
{{Code|lang=bash|code=
 +
cmake -DCMAKE_BUILD_TYPE=Debug ../freecad-source
 +
}}
 +
<translate>
 +
 
 +
==== For a Release build ==== <!--T:156-->
 +
 
 +
<!--T:270-->
 +
Create a {{incode|Release}} build to test code that doesn't crash. A {{incode|Release}} build will run much faster than a {{incode|Debug}} build.
 +
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
{{Code|lang=bash|code=
./configure
+
cmake -DCMAKE_BUILD_TYPE=Release ../freecad-source
</syntaxhighlight>
+
}}
 
<translate>
 
<translate>
<!--T:60-->
+
 
To get everything configured. If you want an overview of all options you can specify, you can type
+
==== Building against Python 3 and Qt5 ==== <!--T:272-->
 +
 
 +
<!--T:271-->
 +
By default, FreeCAD builds for Python 2 and Qt4. Since these two packages are obsolete, it is better to build for Python 3 and Qt5.
 +
 
 +
<!--T:273-->
 +
In a modern Linux distribution you only need to provide two variables specifying the use of Qt5, and the path to the Python interpreter.
 +
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
{{Code|lang=bash|code=
./configure --help
+
cmake -DBUILD_QT5=ON -DPYTHON_EXECUTABLE=/usr/bin/python3 ../freecad-source
</syntaxhighlight>
+
}}
 
<translate>
 
<translate>
<!--T:61-->
+
 
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
+
==== Building for a specific Python version ==== <!--T:220-->
 +
 
 +
<!--T:274-->
 +
If the default {{incode|python}} executable in your system is a symbolic link to Python 2, {{incode|cmake}} will try to configure FreeCAD for this version. You can choose another version of Python by giving the path to a specific executable:
 +
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
{{Code|lang=bash|code=
make
+
cmake -DPYTHON_EXECUTABLE=/usr/bin/python3 ../freecad-source
</syntaxhighlight>
+
}}
 
<translate>
 
<translate>
<!--T:62-->
+
 
If any error occurs while building from sources, please double-check this page and README.Linux file, then you could jump to the [[Tracker|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, do
+
<!--T:275-->
 +
If that doesn't work, you may have to define additional variables pointing to the desired Python libraries and include directories:
 +
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
{{Code|lang=bash|code=
make install
+
cmake -DPYTHON_EXECUTABLE=/usr/bin/python3.6 \
</syntaxhighlight>
+
    -DPYTHON_INCLUDE_DIR=/usr/include/python3.6m \
 +
    -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.6m.so \
 +
    -DPYTHON_PACKAGES_PATH=/usr/lib/python3.6/site-packages/ \
 +
    ../freecad-source
 +
}}
 
<translate>
 
<translate>
<!--T:63-->
+
 
to install it onto your machine. The default install directory is
+
<!--T:221-->
 +
It is possible to have several independent versions of Python in the same system, so the locations and version numbers of your Python files will depend on your particular Linux distribution. Use {{incode|python3 -V}} to display the version of Python that you are using currently; only the first two numbers are necessary; for example, if the result is {{incode|Python 3.6.8}}, you need to specify the directories that relate to the 3.6 version. If you don't know the right directories, try searching for them with the {{incode|locate}} command.
 +
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
{{Code|code=
~/FreeCAD
+
locate python3.6
</syntaxhighlight>
+
}}
 
<translate>
 
<translate>
<!--T:64-->
+
 
It will be installed in a FreeCAD folder in your home folder, so you don't need root privileges. Instead of make install, you can also do
+
<!--T:276-->
 +
You may use {{incode|python3 -m site}} in a terminal to determine the {{incode|site-packages}} directory, or {{incode|dist-packages}} for Debian systems.
 +
 
 +
==== Building with Qt Creator against Python 3 and Qt5 ==== <!--T:246-->
 +
 
 +
<!--T:247-->
 +
To compile in Qt Creator add the appropriate variables to the bottom of {{MenuCommand|Projects → Manage Kits → Kits → Default (or your kit) → CMake Configuration}}. Again, specify the correct paths and Python version that you want to use.
 +
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
{{Code|code=
checkinstall
+
PYTHON_EXECUTABLE=/usr/bin/python3.7
</syntaxhighlight>
+
PYTHON_INCLUDE_DIR=/usr/include/python3.7m
 +
PYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.7m.so
 +
PYTHON_PACKAGES_PATH=/usr/lib/python3.7/site-packages
 +
BUILD_QT5=ON
 +
}}
 
<translate>
 
<translate>
<!--T:65-->
 
In this way FreeCAD will be installed by your package management system, so you can uninstall it easily later. But since all of FreeCAD installation resides into one single directory, just removing the FreeCAD directory is a valid way to uninstall too.
 
  
==== Qt designer plugin ==== <!--T:66-->
+
<!--T:250-->
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
+
Go to {{MenuCommand|Projects → Run → Run Configuration}} and choose {{incode|FreeCADMain}} to compile the graphical version of FreeCAD, or {{incode|FreeCADMainCMD}} to compile only the command line version.
 +
 
 +
==== Qt designer plugin ==== <!--T:222-->
 +
If you want to develop Qt code for FreeCAD, you'll need the Qt Designer plugin that provides all custom widgets of FreeCAD.
 +
 
 +
<!--T:277-->
 +
Go into an auxiliary directory of the source code, the run {{incode|qmake}} with the indicated project file to create a {{incode|Makefile}}; then run {{incode|make}} to compile the plugin.
 +
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
{{Code|lang=bash|code=
freecad/src/Tools/plugins/widget
+
cd freecad-source/src/Tools/plugins/widget
</syntaxhighlight>
+
qmake plugin.pro
 +
make
 +
}}
 
<translate>
 
<translate>
<!--T:67-->
+
 
So far we don't provide a makefile -- but calling
+
<!--T:303-->
 +
If you are compiling for Qt5, make sure the {{incode|qmake}} binary is the one for this version, so that the resulting {{incode|Makefile}} contains the necessary information for Qt5.
 +
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
{{Code|lang=bash|code=
qmake plugin.pro
+
cd freecad-source/src/Tools/plugins/widget
</syntaxhighlight>
+
$QT_DIR/bin/qmake plugin.pro
 +
make
 +
}}
 
<translate>
 
<translate>
<!--T:68-->
+
 
creates it. Once that's done, calling
+
<!--T:304-->
 +
where {{incode|$QT_DIR}} is the directory that stores Qt binary libraries, for example, {{incode|/usr/lib/x86_64-linux-gnu/qt5}}.
 +
 
 +
<!--T:289-->
 +
The library created is {{incode|libFreeCAD_widgets.so}}, which needs to be copied to {{incode|$QT_DIR/plugins/designer}}.
 +
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
{{Code|lang=bash|code=
make
+
sudo cp libFreeCAD_widgets.so $QT_DIR/plugins/designer
</syntaxhighlight>
+
}}
 
<translate>
 
<translate>
<!--T:69-->
 
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 ==== <!--T:70-->
+
==== External or internal Pivy ==== <!--T:217-->
If you feel bold enough to dive in the code, you could take advantage to build and consult Doxygen generated FreeCAD's [[Source documentation]]
+
 
 +
<!--T:218-->
 +
Previously, a version of Pivy was included in the source code of FreeCAD (internal). If you wanted to use your system's copy of Pivy (external), you needed to use <code>-DFREECAD_USE_EXTERNAL_PIVY=1</code>.
 +
 
 +
<!--T:279-->
 +
Using external Pivy became the default during development of FreeCAD 0.16, therefore this option does not need to be set manually anymore.
 +
 
 +
==== Doxygen documentation ==== <!--T:226-->
 +
If you have Doxygen installed you can build the source code documentation. See [[source documentation]] for instructions.
 +
 
 +
=== Additional documentation === <!--T:291-->
 +
 
 +
<!--T:292-->
 +
The source code of FreeCAD is very extensive, and with CMake it's possible to configure many options. Learning to use CMake fully may be useful to choose the right options for your particular needs.
 +
* [https://cmake.org/documentation/ CMake Reference Documentation] by Kitware.
 +
* [https://preshing.com/20170511/how-to-build-a-cmake-based-project/ How to Build a CMake-Based Project] (blog) by Preshing on programming.
 +
* [https://preshing.com/20170522/learn-cmakes-scripting-language-in-15-minutes/ Learn CMake's Scripting Language in 15 Minutes] (blog) by Preshing on programming.
  
 
=== Making a debian package === <!--T:71-->
 
=== Making a debian package === <!--T:71-->
If you plan to build a Debian package out of the sources you need to install those packages first:
+
If you plan to build a Debian package out of the sources you need to install certain packages first:
 +
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
{{Code|lang=bash|code=
dh-make
+
sudo apt install dh-make devscripts lintian
devscripts
+
}}
lintian (optional, used for checking if packages are standard-compliant)
 
</syntaxhighlight>
 
 
<translate>
 
<translate>
 +
 
<!--T:72-->
 
<!--T:72-->
To build a package open a console, simply go to the FreeCAD directory and call
+
Go to the FreeCAD directory and call
 +
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
{{Code|lang=bash|code=
debuild
+
debuild
</syntaxhighlight>
+
}}
 
<translate>
 
<translate>
 +
 
<!--T:73-->
 
<!--T:73-->
Once the package is built, you can use lintian to check if the package contains errors
+
Once the package is built, you can use {{incode|lintian}} to check if the package contains errors
lintian your-fresh-new-freecad-package.deb (replace by the name of the package you just created)
+
 
 +
</translate>
 +
{{Code|lang=bash|code=
 +
lintian freecad-package.deb
 +
}}
 +
<translate>
 +
 
 +
== Updating the source code == <!--T:149-->
 +
 
 +
<!--T:280-->
 +
The CMake system allows you to intelligently update the source code, and only recompile what has changed, making subsequent compilations faster.
 +
 
 +
<!--T:281-->
 +
Move to the location where the FreeCAD source code was first downloaded, and pull the new code:
 +
 
 +
</translate>
 +
{{Code|lang=bash|code=
 +
cd freecad-source
 +
git pull
 +
}}
 +
<translate>
 +
 
 +
<!--T:150-->
 +
Then move into the build directory where the code was compiled initially, and run {{incode|cmake}} specifying the present directory (denoted by a dot); then trigger the re-compilation with {{incode|make}}.
 +
 
 +
</translate>
 +
{{Code|lang=bash|code=
 +
cd ../freecad-build
 +
cmake .
 +
make -j$(nproc --ignore=2)
 +
}}
 +
<translate>
  
 
== Troubleshooting == <!--T:74-->
 
== Troubleshooting == <!--T:74-->
  
=== Note for 64bit systems === <!--T:75-->
+
=== For 64 bit systems === <!--T:75-->
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:
+
When building FreeCAD for 64-bit there is a known issue with the OpenCASCADE (OCCT) 64-bit package. To get FreeCAD running properly you might need to run the {{incode|configure}} script and set additional {{incode|CXXFLAGS}}:
 +
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
{{Code|lang=bash|code=
./configure CXXFLAGS="-D_OCC64"
+
./configure CXXFLAGS="-D_OCC64"
</syntaxhighlight>
+
}}
 
<translate>
 
<translate>
 +
 
<!--T:76-->
 
<!--T:76-->
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.
+
For Debian based systems this option is not needed when using the pre-built OpenCASCADE packages because these ones set the proper {{incode|CXXFLAGS}} internally.
  
=== Automake macros === <!--T:77-->
+
== Automatic build scripts == <!--T:142-->
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 soqt.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.
+
Here is all what you need for a complete build of FreeCAD. It's a one-script-approach and works on a freshly installed Linux distribution. The commands will ask for the root password for installation of packages and new online repositories. 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.
  
=== Fedora 13 === <!--T:78-->
+
<!--T:143-->
 +
If you have such a script for your preferred distribution, please discuss it on the [https://forum.freecadweb.org/viewforum.php?f=21&sid=e3c22dca9da076fefb56b1d5c5fb3134 FreeCAD forum] so we can incorporate it.
  
<!--T:79-->
+
</translate>
To build & install FreeCAD on Fedora 13, a few tips and tricks are needed:
+
<div class="mw-collapsible mw-collapsed toccolours">
* Install a bunch of required packages, most are available from the Fedora 13 repositories
+
<translate>
* Download and build xerces
 
* Download and build OpenCascade. Need to point it to xmu: ./configure --with-xmu-include=/usr/include/X11/Xmu --with-xmu-library=/usr/lib
 
* 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: ./configure --with-qt4-include=/usr/include --with-qt4-bin=/usr/lib/qt4/bin --with-occ-lib=/usr/local/lib --with-occ-include=/usr/local/inc --with-xercesc-lib=/usr/local/lib
 
* 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 !
 
* make install
 
  
=== Ubuntu Lucid === <!--T:80-->
+
=== Ubuntu === <!--T:315-->  
In Ubuntu Lucid, you don't need the qtwebkit-dev, since it is included into qt4-dev.
 
  
== Automatic build scripts == <!--T:81-->
+
</translate>
Here is all what you need for a complete build of FreeCAD. It's a one-script-approach
+
<div class="mw-collapsible-content">
and works on a fresh installed distro. The commands will ask for root password
+
<translate>
(for installation of packages) and sometime to acknowledge a fingerprint for
 
an external repository server or https-subversion repository. This scripts should
 
run on 32 and 64 bit versions. They are written for distinct version, but are
 
also likely to run on a later version with or without minor changes.
 
  
<!--T:82-->
+
<!--T:163-->
If you have such a script for your preferred distro, please send it! We will
+
These scripts provide a reliable way to install the correct set of dependencies required to build and run FreeCAD on Ubuntu. They make use of the Ubuntu personal package archives (PPA), and should work on any version of Ubuntu targeted by the PPA. The [https://launchpad.net/~freecad-maintainers/+archive/ubuntu/freecad-daily freecad-daily] PPA targets recent versions of Ubuntu, while the [https://launchpad.net/~freecad-maintainers/+archive/ubuntu/freecad-stable freecad-stable] PPA targets officially supported versions of Ubuntu.
incorporate it into this article.
 
  
<!--T:83-->
+
<!--T:164-->
Note that this script starts by adding the [https://launchpad.net/~freecad-maintainers/+archive/freecad-daily 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.
+
This script installs the daily compiled snapshot of FreeCAD and its dependencies. It adds the daily repository, gets the dependencies to build this version, and installs the required packages. Afterwards it proceeds to pull the source code into a particular directory, creates a build directory and changes into it, configures the compilation environment with {{incode|cmake}}, and finally builds the entire program with {{incode|make}}. Save the script to a file, make it executable, and run it, but don't use {{incode|sudo}}; superuser privileges will be asked only for selected commands.
  
=== Ubuntu 10.04 LTS - Lucid Lynx / Ubuntu 10.10 Maverick Meerkat / Ubuntu 11.04 Natty Narwhal === <!--T:84-->
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
{{Code|lang=bash|code=
sudo add-apt-repository ppa:freecad-maintainers/freecad-daily && sudo apt-get update
+
#!/bin/sh
sudo apt-get install build-essential python libcoin60-dev libsoqt4-dev \
+
sudo add-apt-repository --enable-source ppa:freecad-maintainers/freecad-daily && sudo apt-get update
libxerces-c2-dev libboost-dev libboost-date-time-dev libboost-filesystem-dev \
+
sudo apt-get build-dep freecad-daily
libboost-graph-dev libboost-iostreams-dev libboost-program-options-dev \
+
sudo apt-get install freecad-daily
libboost-serialization-dev libboost-signals-dev libboost-regex-dev libboost-thread-dev \
+
 
libqt4-dev qt4-dev-tools python2.7-dev libopencascade-dev libsoqt4-dev \
+
git clone https://github.com/FreeCAD/FreeCAD.git freecad-source
libode-dev subversion cmake libeigen2-dev libsimage-dev python-qt4 \
+
mkdir freecad-build
libtool autotools-dev automake bison flex gfortran libeigen3-dev libqtwebkit-dev git
+
cd freecad-build
+
cmake -DBUILD_QT5=ON -DPYTHON_EXECUTABLE=/usr/bin/python3 ../freecad-source
# checkout the latest source
+
make -j$(nproc --ignore=2)
git clone git://free-cad.git.sourceforge.net/gitroot/free-cad/free-cad freecad
+
}}
+
<translate>
# go to source dir
 
cd freecad
 
 
# build configuration
 
cmake .
 
 
# build FreeCAD
 
make
 
 
# test FreeCAD
 
cd bin
 
./FreeCAD -t 0
 
  
# use FreeCAD
+
<!--T:166-->
./FreeCAD
+
If you wish, you can uninstall the pre-compiled version of FreeCAD ({{incode|freecad-daily}}) while leaving the dependencies in place, however, leaving this package installed will allow the package manager to keep its dependencies up to date as well; this is mostly useful if you intend to follow the development of FreeCAD, and constantly update and compile the sources from the Git repository.
  
# Update latest version
+
<!--T:165-->
 +
The previous script assumes that you want to compile the latest version of FreeCAD, so you are using the "daily" repository to get the dependencies. However, you can instead get the build dependencies of the "stable" version for your current Ubuntu release. If this is the case, replace the top part of the previous script with the following instructions. For Ubuntu 12.04, omit {{incode|--enable-source}} from the command.
  
# go to source dir
+
</translate>
cd freecad
+
{{Code|lang=bash|code=
+
#!/bin/sh
# Update source
+
sudo add-apt-repository --enable-source ppa:freecad-maintainers/freecad-stable && sudo apt-get update
git pull
+
sudo apt-get build-dep freecad
+
sudo apt-get install freecad
# build configuration
+
}}
cmake .
 
 
# build FreeCAD
 
make
 
</syntaxhighlight>
 
 
<translate>
 
<translate>
  
 +
<!--T:295-->
 +
Once you install the {{incode|freecad}} package from the {{incode|freecad-stable}} repository, it will supersede the FreeCAD executable that is available from the Universe Ubuntu repository. The executable will be named simply {{incode|freecad}}, and not {{incode|freecad-stable}}.
  
=== OpenSUSE 12.2 === <!--T:85-->
 
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
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
</div>
# install needed packages for development
+
</div>
sudo zypper install gcc cmake OpenCASCADE-devel libXerces-c-devel \
+
<div class="mw-collapsible mw-collapsed toccolours">
python-devel libqt4-devel python-qt4 Coin-devel SoQt-devel boost-devel \
 
libode-devel libQtWebKit-devel libeigen3-devel gcc-fortran git swig
 
 
# create new dir, and go into it
 
mkdir FreeCAD-Compiled
 
cd FreeCAD-Compiled
 
 
# get the source
 
git clone git://free-cad.git.sourceforge.net/gitroot/free-cad/free-cad
 
 
# Now you will have subfolder in this location called free-cad. It contains the source
 
 
# make another dir for compilation, and go into it
 
mkdir FreeCAD-Build1
 
cd FreeCAD-Build1
 
 
# build configuration
 
cmake ../free-cad
 
 
# build FreeCAD
 
make
 
 
# test FreeCAD
 
cd bin
 
./FreeCAD -t 0
 
</syntaxhighlight>
 
 
<translate>
 
<translate>
<!--T:86-->
+
 
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
+
=== OpenSUSE 12.2 === <!--T:297-->
 +
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
<div class="mw-collapsible-content">
# go into free-cad dir created earlier
 
cd free-cad
 
 
# pull
 
git pull
 
 
# get back to previous dir
 
cd ..
 
 
# Now repeat last few steps from before.
 
 
# make another dir for compilation, and go into it
 
mkdir FreeCAD-Build2
 
cd FreeCAD-Build2
 
 
# build configuration
 
cmake ../free-cad
 
 
# build FreeCAD
 
make
 
 
# test FreeCAD
 
cd bin
 
./FreeCAD -t 0
 
</syntaxhighlight>
 
 
<translate>
 
<translate>
  
 +
<!--T:316-->
 +
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
  
=== OpenSUSE 12.1 === <!--T:87-->
 
For FreeCAD 0.13 unstable you need to add Eigen3 and swig libraries, that don't seem to be in standard repos. You can get them with one-click install here:
 
 
<!--T:88-->
 
Eigen3:
 
http://software.opensuse.org/search?q=eigen3&baseproject=openSUSE%3A12.1&lang=en&exclude_debug=true
 
 
<!--T:89-->
 
swig:
 
http://software.opensuse.org/search?q=swig&baseproject=openSUSE%3A12.1&lang=en&exclude_debug=true
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
{{Code|lang=bash|code=
# install needed packages for development
+
# install needed packages for development
sudo zypper install gcc cmake OpenCASCADE-devel libXerces-c-devel \
+
sudo zypper install gcc cmake OpenCASCADE-devel libXerces-c-devel \
python-devel libqt4-devel python-qt4 Coin-devel SoQt-devel boost-devel \
+
python-devel libqt4-devel python-qt4 Coin-devel SoQt-devel boost-devel \
libode-devel libQtWebKit-devel libeigen3-devel gcc-fortran git
+
libode-devel libQtWebKit-devel libeigen3-devel gcc-fortran git swig
 
   
 
   
# create new dir, and go into it
+
# create new dir, and go into it
mkdir FreeCAD-Compiled  
+
mkdir FreeCAD-Compiled  
cd FreeCAD-Compiled
+
cd FreeCAD-Compiled
 
   
 
   
# get the source
+
# get the source
git clone git://free-cad.git.sourceforge.net/gitroot/free-cad/free-cad
+
git clone https://github.com/FreeCAD/FreeCAD.git free-cad
 
   
 
   
# Now you will have subfolder in this location called free-cad. It contains the source
+
# Now you will have subfolder in this location called free-cad. It contains the source
 
   
 
   
# make another dir for compilation, and go into it
+
# make another dir for compilation, and go into it
mkdir FreeCAD-Build1
+
mkdir FreeCAD-Build1
cd FreeCAD-Build1  
+
cd FreeCAD-Build1  
 
   
 
   
# build configuration  
+
# build configuration  
cmake ../free-cad
+
cmake ../free-cad
 
   
 
   
# build FreeCAD
+
# build FreeCAD
make
+
make
 
   
 
   
# test FreeCAD
+
# test FreeCAD
cd bin
+
cd bin
./FreeCAD -t 0
+
./FreeCAD -t 0
</syntaxhighlight>
+
}}
 
<translate>
 
<translate>
<!--T:90-->
+
 
 +
<!--T:317-->
 
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
 
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
 +
 
</translate>
 
</translate>
<syntaxhighlight>
+
{{Code|lang=bash|code=
# go into free-cad dir created earlier
+
# go into free-cad dir created earlier
cd free-cad
+
cd free-cad
 
   
 
   
# pull
+
# pull
git pull
+
git pull
 
   
 
   
# get back to previous dir
+
# get back to previous dir
cd ..
+
cd ..
 
   
 
   
# Now repeat last few steps from before.
+
# Now repeat last few steps from before.
 
   
 
   
# make another dir for compilation, and go into it
+
# make another dir for compilation, and go into it
mkdir FreeCAD-Build2
+
mkdir FreeCAD-Build2
cd FreeCAD-Build2
+
cd FreeCAD-Build2
 
   
 
   
# build configuration  
+
# build configuration  
cmake ../free-cad
+
cmake ../free-cad
 
   
 
   
# build FreeCAD
+
# build FreeCAD
make
+
# Note: to speed up build use all CPU cores: make -j$(nproc)
 +
make
 
   
 
   
# test FreeCAD
+
# test FreeCAD
cd bin
+
cd bin
./FreeCAD -t 0
+
./FreeCAD -t 0
</syntaxhighlight>
+
}}
 +
</div>
 +
</div>
 +
 
 +
<div class="mw-collapsible mw-collapsed toccolours">
 
<translate>
 
<translate>
  
 +
=== Debian Squeeze === <!--T:318-->
  
=== OpenSuse 11.2 === <!--T:91-->
 
This script is '''not working''' at the moment because:
 
* libXerces-c-devel seams to be disappeared ....
 
 
</translate>
 
</translate>
<syntaxhighlight>  
+
<div class="mw-collapsible-content">
# install needed packages for development
+
{{Code|lang=bash|code=
sudo zypper install gcc cmake subversion OpenCASCADE-devel \
+
# get the needed tools and libs
libXerces-c-devel python-devel libqt4-devel  python-qt4 \
+
sudo apt-get install build-essential python libcoin60-dev libsoqt4-dev \
Coin-devel SoQt-devel boost-devel libode-devel libQtWebKit-devel \
+
libxerces-c2-dev libboost-dev libboost-date-time-dev libboost-filesystem-dev \
libeigen2-devel gcc-fortran
+
libboost-graph-dev libboost-iostreams-dev libboost-program-options-dev \
 +
libboost-serialization-dev libboost-signals-dev libboost-regex-dev \
 +
libqt4-dev qt4-dev-tools python2.5-dev \
 +
libsimage-dev libopencascade-dev \
 +
libsoqt4-dev libode-dev subversion cmake libeigen2-dev python-pivy \
 +
libtool autotools-dev automake gfortran
 
   
 
   
# get the source
+
# checkout the latest source
git clone git://free-cad.git.sourceforge.net/gitroot/free-cad/free-cad freecad
+
git clone https://github.com/FreeCAD/FreeCAD.git freecad
 
   
 
   
# go to source dir
+
# go to source dir
cd freecad
+
cd freecad
 
   
 
   
# build configuration  
+
# build configuration  
cmake .
+
cmake .
 
   
 
   
# build FreeCAD
+
# build FreeCAD
nice make
+
# Note: to speed up build use all CPU cores: make -j$(nproc)
 +
make
 
   
 
   
# test FreeCAD
+
# test FreeCAD
cd bin
+
cd bin
./FreeCAD -t 0
+
./FreeCAD -t 0
</syntaxhighlight>
+
}}
 +
</div>
 +
</div>
 +
<div class="mw-collapsible mw-collapsed toccolours">
 
<translate>
 
<translate>
  
 +
=== Fedora 27/28/29 === <!--T:319-->
  
=== OpenSuse 11.1 === <!--T:92-->
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
<div class="mw-collapsible-content">
# additional repository (for OpenCascade)
 
sudo zypper -p http://packman.unixheads.com/suse/11.1/
 
 
# install needed packages for development
 
sudo zypper install gcc cmake subversion OpenCASCADE-devel \
 
libXerces-c-devel python-devel libqt4-devel  python-qt4 \
 
Coin-devel SoQt-devel boost-devel libode-devel libQtWebKit-devel \
 
libeigen2-devel
 
 
# get the source
 
git clone git://free-cad.git.sourceforge.net/gitroot/free-cad/free-cad freecad
 
 
# go to source dir
 
cd freecad
 
 
# build configuration
 
cmake .
 
 
# build FreeCAD
 
nice make
 
 
# test FreeCAD
 
cd bin
 
./FreeCAD -t 0
 
</syntaxhighlight>
 
 
<translate>
 
<translate>
  
 +
<!--T:320-->
 +
Posted by user [[http://forum.freecadweb.org/memberlist.php?mode=viewprofile&u=3666 PrzemoF]] in the forum.
  
=== Debian Squeeze === <!--T:93-->
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
{{Code|lang=bash|code=
# get the needed tools and libs
+
#!/bin/bash
sudo apt-get install build-essential python libcoin60-dev libsoqt4-dev \
+
 
libxerces-c2-dev libboost-dev libboost-date-time-dev libboost-filesystem-dev \
+
ARCH=$(arch)
libboost-graph-dev libboost-iostreams-dev libboost-program-options-dev \
+
 
  libboost-serialization-dev libboost-signals-dev libboost-regex-dev \
+
MAIN_DIR=FreeCAD
libqt4-dev qt4-dev-tools python2.5-dev \
+
BUILD_DIR=build
libsimage-dev libopencascade-dev \
+
 
libsoqt4-dev libode-dev subversion cmake libeigen2-dev python-pivy \
+
#FEDORA_VERSION=27
libtool autotools-dev automake gfortran
+
#FEDORA_VERSION=28
+
FEDORA_VERSION=29
# checkout the latest source
+
 
git clone git://free-cad.git.sourceforge.net/gitroot/free-cad/free-cad freecad
+
PACKAGES="gcc cmake gcc-c++ boost-devel zlib-devel swig eigen3 qt-devel \
+
shiboken shiboken-devel pyside-tools python-pyside python-pyside-devel xerces-c \
# go to source dir
+
xerces-c-devel OCE-devel smesh graphviz python-pivy python-matplotlib tbb-devel \
cd freecad
+
  freeimage-devel Coin3 Coin3-devel med-devel vtk-devel"
+
 
# build configuration
+
FEDORA_29_PACKAGES="boost-python2 boost-python3 boost-python2-devel boost-python3-devel"
cmake .
+
 
+
if [ "$FEDORA_VERSION" = "29" ]; then
# build FreeCAD
+
    PACKAGES="$PACKAGES $FEDORA_29_PACKAGES"
make
+
fi
+
 
# test FreeCAD
+
echo "Installing packages required to build FreeCAD"
cd bin
+
sudo dnf -y install $PACKAGES
./FreeCAD -t 0
+
cd ~
</syntaxhighlight>
+
mkdir $MAIN_DIR <nowiki>||</nowiki> { echo "~/$MAIN_DIR already exist. Quitting.."; exit; }
 +
cd $MAIN_DIR
 +
git clone https://github.com/FreeCAD/FreeCAD.git
 +
mkdir $BUILD_DIR <nowiki>||</nowiki> { echo "~/$BUILD_DIR already exist. Quitting.."; exit; }
 +
cd $BUILD_DIR
 +
cmake ../FreeCAD  
 +
make -j$(nproc)
 +
}}
 +
</div>
 +
</div>
 +
 
 +
<div class="mw-collapsible mw-collapsed toccolours">
 
<translate>
 
<translate>
  
== Updating the source code == <!--T:94-->
+
=== Arch using AUR === <!--T:321-->
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:
+
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
<div class="mw-collapsible-content">
cd freecad (or where you cloned the source code the first time)
 
git pull (if you are using git)
 
</syntaxhighlight>
 
 
<translate>
 
<translate>
<!--T:95-->
+
 
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:
+
<!--T:322-->
 +
[https://aur.archlinux.org/ Arch User Repository (AUR)] is a collection user made recipes to build packages which are not officially supported by distribution maintainers / community. They are usually safe. You can see who maintain the package and for how long he did. It is recommended to check construction files. Also non open source software are available in this area even if maintained by the official owning company.
 +
 
 +
<!--T:323-->
 +
Prerequisite : git
 +
 
 +
<!--T:324-->
 +
Steps :
 +
#Open a terminal. Optionally create a directory eg. {{incode | mkdir git}}. Optionally change directory eg. {{incode|cd git}}.
 +
#Clone the AUR repository : {{incode|git clone http://aur.archlinux.org/packages/freecad-git}}
 +
#Enter AUR repository folder : {{incode|cd freecad-git}}
 +
#Compile using [https://wiki.archlinux.org/index.php/Makepkg Arch makepkg] : {{incode|makepkg -s}}. The -s or --syncdeps flag  will also install required dependencies.
 +
#Install created package : {{incode|makepkg --install}} or double click on the pkgname-pkgver.pkg.tar.xz inside your file browser.
 +
 
 +
<!--T:325-->
 +
To update FreeCAD to latest build just repeat from step 3. Update AUR repo when there is some breaking change in the recipe or new features using {{incode|git checkout -f}} inside the folder.
 +
 
 
</translate>
 
</translate>
<syntaxhighlight>
+
</div>
cd ../freecad-build (or wherever your build directory is located)
+
</div>
 
cmake .
 
 
make
 
</syntaxhighlight>
 
 
<translate>
 
<translate>
 +
 
<!--T:96-->
 
<!--T:96-->
 
{{docnav|CompileOnWindows|CompileOnMac}}
 
{{docnav|CompileOnWindows|CompileOnMac}}
 +
 +
<!--T:205-->
 +
{{Userdocnavi}}
 +
 +
<!--T:195-->
 
[[Category:Developer Documentation]]
 
[[Category:Developer Documentation]]
 +
 
</translate>
 
</translate>
 
<languages/>
 

Latest revision as of 10:25, 8 October 2019

Other languages:
български • ‎čeština • ‎Deutsch • ‎English • ‎español • ‎français • ‎italiano • ‎한국어 • ‎polski • ‎português • ‎português do Brasil • ‎română • ‎русский • ‎svenska • ‎Türkçe • ‎中文(中国大陆)‎

On recent linux distributions, FreeCAD is generally easy to build, since all dependencies are usually provided by the package manager. It basically involves 3 steps:

  1. Getting the FreeCAD source code
  2. Getting the dependencies or packages that FreeCAD depends on
  3. Configure with cmake and compile with make

Below, you'll find detailed explanations of the whole process, some build scripts, and particularities you might encounter. If you find anything wrong or out of date in the text below (Linux distributions change often), or if you use a distribution which is not listed, discuss the issue in the forum, and help us correct it.

FreeCAD source compilation workflow.svg

General workflow to compile FreeCAD from source. The third party dependencies must be in the system, as well as the FreeCAD source code itself. CMake configures the system so that with a single make instruction the entire project is compiled.


Getting the source

Git

The best way to get the code is to clone the read-only Git repository. For this you need the git program which can be easily installed in most Linux distributions, and it can also be obtained from the official website.

This will place a copy of the latest version of the FreeCAD source code in a new directory called freecad-source.

sudo apt install git
git clone https://github.com/FreeCAD/FreeCAD.git freecad-source

For more information on using Git, and contributing code to the project, see Source code management.

Source archive

Alternatively you can download the source as an archive, a .zip or .tar.gz file, and unpack it in the desired directory.

Getting the dependencies

To compile FreeCAD you have to install the requisite dependencies mentioned in Third Party Libraries; the packages that contain these dependencies are listed below for different Linux distributions. Please note that the names and availability of the libraries will depend on your particular distribution; if your distribution is old, some packages may be unavailable of have a different name. In this case, look in the older and non-conventional distributions section below.

Once you have all the dependencies installed proceed to compile FreeCAD.

Please note that FreeCAD's source code is around 500 MB in size; it may be three times as big if you clone the Git repository with its entire modification history. Getting all dependencies may require downloading 500 MB or more of new files; when these files are unpacked they may require 1500 MB or more in space. Also beware that the compilation process may generate up to 1500 MB of additional files as the system copies and modifies the entire source code. Therefore, be sure you have enough free space in your hard drive, at least 4 GB, when attempting compilation.

Debian and Ubuntu

On Debian-based systems (Debian, Ubuntu, Mint, etc.) it is quite easy to get all needed dependencies installed. Most of the libraries are available via apt or the Synaptic package manager.

If you already installed FreeCAD from the official repositories, you can install its build dependencies with this single line of code in a terminal:

sudo apt build-dep freecad

However, if the version of FreeCAD in the repositories is old, the dependencies may be the wrong ones to compile a recent version of FreeCAD. Therefore, please verify that you have installed the following packages.

These packages are essential for any sort of compilation to succeed:

  • build-essential, installs the C and C++ compilers, the C development libraries, and the make program.
  • cmake, essential tool to configure the source of FreeCAD. You may also wish to install cmake-gui and cmake-curses-gui for a graphical option.
  • libtool, essential tools to produce shared libraries.
  • lsb-release, the standard base reporting utility is normally already installed in a Debian system, and allows you to programmatically distinguish between a pure Debian installation or a variant, such as Ubuntu or Linux Mint. Do not remove this package, as many other system packages may depend on it.

Compilation of FreeCAD uses the Python language, and it's also used at runtime as a scripting language. If you are using a Debian based distribution the Python interpreter is normally already installed.

  • python3
  • swig, the tool that creates interfaces between C++ code and Python.

Please check that you have Python 3 installed. Python 2 was obsoleted in 2019, so new development in FreeCAD is not tested with this version of the language.

The Boost libraries need to be installed:

  • libboost-dev
  • libboost-date-time-dev
  • libboost-filesystem-dev
  • libboost-graph-dev
  • libboost-iostreams-dev
  • libboost-program-options-dev
  • libboost-python-dev
  • libboost-regex-dev
  • libboost-serialization-dev
  • libboost-signals-dev
  • libboost-thread-dev

The Coin libraries need to be installed:

  • libcoin80-dev, for Debian Jessie, Stretch, Ubuntu 16.04 to 18.10, or
  • libcoin-dev, for Debian Buster, Ubuntu 19.04 and newer, as well as for Ubuntu 18.04/18.10 with the freecad-stable/freecad-daily PPAs added to your software sources.

Several libraries that deal with mathematics, triangulated surfaces, sorting, meshes, computer vision, cartographic projections, 3D visualization, the X11 Window system, XML parsing, and Zip file reading:

  • libeigen3-dev
  • libgts-bin
  • libgts-dev
  • libkdtree++-dev
  • libmedc-dev
  • libopencv-dev or libcv-dev
  • libproj-dev
  • libvtk7-dev or libvtk6-dev
  • libx11-dev
  • libxerces-c-dev
  • libzipios++-dev

Python 2 and Qt4

This is not recommended for newer installations as both Python 2 and Qt4 are obsolete.

To compile FreeCAD for Debian Jessie, Stretch, Ubuntu 16.04, using Python 2 and Qt4, install the following dependencies.

  • qt4-dev-tools
  • libqt4-dev
  • libqt4-opengl-dev
  • libqtwebkit-dev
  • libshiboken-dev
  • libpyside-dev
  • pyside-tools
  • python-dev
  • python-matplotlib
  • python-pivy
  • python-ply
  • python-pyside

Python 3 and Qt5

To compile FreeCAD for Debian Buster, Ubuntu 19.04 and newer, as well as Ubuntu 18.04/18.10 with the freecad-stable/freecad-daily PPAs added to your software sources, install the following dependencies.

  • qtbase5-dev
  • qttools5-dev
  • libqt5opengl5-dev
  • libqt5svg5-dev
  • libqt5webkit5-dev or qtwebengine5-dev
  • libqt5xmlpatterns5-dev
  • libqt5x11extras5-dev
  • libpyside2-dev
  • libshiboken2-dev
  • pyside2-tools
  • python3-dev
  • python3-matplotlib
  • python3-pivy
  • python3-ply
  • python3-pyside2.qtcore
  • python3-pyside2.qtgui
  • python3-pyside2.qtsvg
  • python3-pyside2.qtwidgets
  • python3-pyside2uic

OpenCascade kernel

The OpenCascade kernel is the core graphics library to create 3D shapes. It exists in an official version OCCT, and a community version OCE. The community version is no longer recommended, as it's outdated.

For Debian Buster and Ubuntu 18.10 and newer, as well as Ubuntu 18.04 with the freecad-stable/freecad-daily PPAs added to your software sources, install the official packages.

  • libocct*-dev
    • libocct-data-exchange-dev
    • libocct-draw-dev
    • libocct-foundation-dev
    • libocct-modeling-algorithms-dev
    • libocct-modeling-data-dev
    • libocct-ocaf-dev
    • libocct-visualization-dev
  • occt-draw

For Debian Jessie, Stretch, Ubuntu 16.04 and newer, install the community edition packages.

  • liboce*-dev
    • liboce-foundation-dev
    • liboce-modeling-dev
    • liboce-ocaf-dev
    • liboce-ocaf-lite-dev
    • liboce-visualization-dev
  • oce-draw

You may install the libraries individually, or using asterisk expansion. Change occ for oce if you want to install the community libraries.

sudo apt install libocct*-dev

Optional packages

Optionally you can also install these extra packages:

  • libsimage-dev, to make Coin support additional image file formats.
  • doxygen and libcoin-doc (or libcoin80-doc for older systems), if you intend to generate source code documentation.
  • libspnav-dev, for 3D input devices support, like the 3Dconnexion "Space Navigator" or "Space Pilot".
  • checkinstall, if you intend to register your installed files into your system's package manager, so you can uninstall it later.

Single command for Python 3 and Qt5

Requires Pyside2 available in Debian buster and the freecad-stable/freecad-daily PPAs.

sudo apt install cmake cmake-gui libboost-date-time-dev libboost-dev libboost-filesystem-dev libboost-graph-dev libboost-iostreams-dev libboost-program-options-dev libboost-python-dev libboost-regex-dev libboost-serialization-dev libboost-signals-dev libboost-thread-dev libcoin-dev libeigen3-dev libgts-bin libgts-dev libkdtree++-dev libmedc-dev libocct-data-exchange-dev libocct-ocaf-dev libocct-visualization-dev libopencv-dev libproj-dev libpyside2-dev libqt5opengl5-dev libqt5svg5-dev libqt5webkit5-dev libqt5x11extras5-dev libqt5xmlpatterns5-dev libshiboken2-dev libspnav-dev libvtk7-dev libx11-dev libxerces-c-dev libzipios++-dev occt-draw pyside2-tools python3-dev python3-matplotlib python3-pivy python3-ply python3-pyside2.qtcore python3-pyside2.qtgui python3-pyside2.qtsvg python3-pyside2.qtwidgets python3-pyside2uic qtbase5-dev qttools5-dev swig

Single command for Python 2 and Qt4

This is not recommended for newer installations as both Python 2 and Qt4 are obsolete.

sudo apt install cmake debhelper dh-exec dh-python libboost-date-time-dev libboost-dev libboost-filesystem-dev libboost-graph-dev libboost-iostreams-dev libboost-program-options-dev libboost-python-dev libboost-regex-dev libboost-serialization-dev libboost-signals-dev libboost-thread-dev libcoin80-dev libeigen3-dev libgts-bin libgts-dev libkdtree++-dev libmedc-dev libocct-data-exchange-dev libocct-ocaf-dev libocct-visualization-dev libopencv-dev libproj-dev libpyside-dev libqt4-dev libqt4-opengl-dev libqtwebkit-dev libshiboken-dev libspnav-dev libvtk6-dev libx11-dev libxerces-c-dev libzipios++-dev lsb-release occt-draw pyside-tools python-dev python-matplotlib python-pivy python-ply swig

Ubuntu 16.04 users please see also the compilation discussion in the forum: Compile on Linux (Kubuntu): CMake can't find VTK.

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 :


Gentoo

Easiest way to check which packages are needed to compile FreeCAD is to check via portage:

emerge -pv freecad

This should give a nice list of extra packages that you need installed on your system.

If FreeCAD is not available on portage, it is available on the waebbl overlay. The issue tracker on the waebbl overlay Github may help guide through some issues you may come across. The overlay provides freecad-9999, which you can choose to compile, or simply use to get the dependencies.

layman -a waebbl

openSUSE

Tumbleweed

The following commands will install the packages required for building FreeCAD with Qt5 and Python 3.

zypper in --no-recommends -t pattern devel_C_C++ devel_qt5

zypper in libqt5-qtbase-devel libqt5-qtsvg-devel libqt5-qttools-devel boost-devel swig libboost_program_options-devel libboost_mpi_python3-devel libboost_system-devel libboost_program_options-devel libboost_regex-devel libboost_python3-devel libboost_thread-devel libboost_system-devel libboost_headers-devel libboost_graph-devel python3 python3-devel python3-matplotlib python3-matplotlib-qt5 python3-pyside2 python3-pyside2-devel python3-pivy gcc gcc-fortran cmake occt-devel libXi-devel opencv-devel libxerces-c-devel Coin-devel SoQt-devel freetype2-devel eigen3-devel libode6 vtk-devel libmed-devel hdf5-openmpi-devel openmpi2-devel netgen-devel freeglut-devel libspnav-devel f2c doxygen dos2unix glew-devel

The following command will install Qt Creator and the GNU Project Debugger.

zypper in libqt5-creator gdb

If any packages are missing, then you can check the Tumbleweed "FreeCAD.spec" file on the Open Build Service.

Also, check to see if there are any patches you need to apply (such as 0001-find-openmpi2-include-files.patch).

Leap

If there is a difference between the available packages on Tumbleweed and Leap, then you can read the Leap "FreeCAD.spec" file on the Open Build Service to determine the required packages.

Arch Linux

You will need the following libraries from the official repositories:

  • boost-libs
  • curl
  • desktop-file-utils
  • glew
  • hicolor-icon-theme
  • jsoncpp
  • libspnav
  • med
  • opencascade
  • shiboken2
  • xerces-c
  • pyside2
  • python-matplotlib
  • python-netcdf4
  • qt5-svg
  • qt5-webkit
  • qt5-webengine
  • boost
  • cmake
  • eigen
  • git
  • gcc-fortran
  • pyside2-tools
  • swig
  • qt5-tools
  • shared-mime-info

Also, make sure to check the AUR for any missing packages that are not on the repositories, currently:

  • coin
  • python-pivy
  • med
sudo pacman -S boost-libs curl desktop-file-utils glew hicolor-icon-theme jsoncpp libspnav med opencascade shiboken2 xerces-c pyside2 python-matplotlib python-netcdf4 qt5-svg qt5-webkit qt5-webengine cmake eigen git gcc-fortran pyside2-tools swig qt5-tools shared-mime-info coin python-pivy med

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 in your package manager. Beware that some of them might have a slightly different package name; search for name, but also libname, name-dev, name-devel, and similar. If that is not possible try compiling those libraries yourself.

FreeCAD requires the GNU g++ compiler version equal or above 3.0.0, as FreeCAD is mostly written in C++. During the compilation some Python scripts are executed, so the Python interpreter has to work properly. To avoid any linker problems it is also a good idea to have the library paths in the LD_LIBRARY_PATH variable or in the ld.so.conf file. This is already done in modern Linux distributions, but may need to be set in older ones.

Pivy

Pivy (Python wrappers to Coin3d) is not needed to build FreeCAD or to start it, but it is needed as a runtime dependency by the Draft Workbench. If you are not going to use this workbench, you won't need Pivy. However, do notice that the Draft Workbench is used internally by other workbenches, like Arch and BIM, so Pivy needs to be installed to use these workbenches as well.

By November 2015 the obsolete version of Pivy included with the FreeCAD source code will no longer compile on many systems. This isn't a big problem as normally you should get Pivy from your distribution's package manager; if you cannot find Pivy, you may have to compile it yourself, see Pivy compilation instructions.

Debug symbols

In order to troubleshoot crashes in FreeCAD, it is useful to have the debug symbols of important dependency libraries such as Qt. For this, try installing the dependency packages that end with -dbg, -dbgsym, -debuginfo or similar, depending on your Linux distribution.

For Ubuntu, you may have to enable especial repositories to be able to see and install these debug packages with the package manager. See Debug Symbol Packages for more information.

Compile FreeCAD

FreeCAD uses CMake as its main build system, as it's available on all major operating systems. Compiling with CMake is usually very simple and happens in two steps.

  1. CMake checks that every needed program and library is present on your system, and generates a Makefile that is configured for the second step. FreeCAD has several configuration options to choose from, but it comes with sensible defaults. Some alternatives are detailed below.
  2. The compilation itself, which is done with the program make, which generates the FreeCAD executables.

Since FreeCAD is a large application, compiling the entire source code can take anywhere from 10 minutes to one hour, depending on your CPU and the number of CPU cores used for compilation.

You can build the code either in or out of the source directory. Out-of-source building is generally the best option.

Out-of-source build

Building in a separate folder is more convenient than building in the same directory where the source code is located as every time you update the source code CMake can intelligently determine which files have changed, and recompile only what is needed. This is very useful when testing different Git branches as you don't confuse the build system.

To build out-of-source, simply create a build directory, freecad-build, distinct from your FreeCAD source folder, freecad-source; then from this build directory point cmake to the right source folder. You can use cmake-gui or ccmake instead of cmake in the instructions below as well. Once cmake finishes configuring the environment, use make to start the actual compilation.

mkdir freecad-build
cd freecad-build
cmake ../freecad-source
make -j$(nproc --ignore=2)

The -j option of make controls how many jobs (files) are compiled in parallel. The nproc program prints the number of CPU cores in your system; by using it together with the -j option you can choose to process as many files as you have cores, in order to speed up overall compilation of the program. In the example above, it will use all cores in your system except two; this will keep your computer responsive for other uses while compilation proceeds in the background. The FreeCAD executable will eventually appear in the freecad-build/bin directory. See also Compiling (speeding up) to improve compilation speed.

In-source building

In-source builds are fine if you want to compile a version of FreeCAD quickly, and don't intend to update the source code often. In this case, you can remove the compiled program and the source just by deleting a single folder.

Change to the source directory, and point cmake to the present directory (denoted by a single point):

cd freecad-source
cmake .
make -j$(nproc --ignore=2)

The FreeCAD executable will then reside in the freecad-source/bin directory.

How to repair your source code directory

If you accidentally performed a compilation inside the source code directory, or added strange files, and would like to restore the contents to only the original source code, you can perform the following steps.

> .gitignore
git clean -df
git reset --hard HEAD

The first line clears the .gitignore file. This ensures that the following clean and reset commands will affect everything in the directory and will not ignore items matching the expressions in .gitignore. The second line deletes all files and directories that are not tracked by the git repository; then the last command will reset any changes to tracked files, including the first command which cleared the .gitignore file.

If you do not clear the source directory, subsequent runs of cmake may not capture new options to the system if the code changes.

Configuration

By passing different options to cmake, you can change how FreeCAD is compiled. The syntax is as follows.

cmake -D <var>:<type>=<value> $SOURCE_DIR

Where $SOURCE_DIR is the directory that contains the source code. The <type> may be omitted in most cases. The space after the -D option may also be omitted.

For example, to avoid building the FEM Workbench:

cmake -D BUILD_FEM:BOOL=OFF ../freecad-source
cmake -DBUILD_FEM=OFF ../freecad-source

All possible variables are listed in the CMakeLists.txt file, located in the toplevel freecad-source directory. In this file, search for the word option to get to the variables that can be set, and see their default values.


# ==============================================================================
# =================   All the options for the build process    =================
# ==============================================================================

option(BUILD_FORCE_DIRECTORY "The build directory must be different to the source directory." OFF)
option(BUILD_GUI "Build FreeCAD Gui. Otherwise you have only the command line and the Python import module." ON)
option(FREECAD_USE_EXTERNAL_ZIPIOS "Use system installed zipios++ instead of the bundled." OFF)
option(FREECAD_USE_EXTERNAL_SMESH "Use system installed smesh instead of the bundled." OFF)
...

Alternatively, use the command cmake -LH to list the current configuration, and thus all variables that can be changed. You may also install and use cmake-gui to launch a graphical interface showing all the variables that can be modified. In the next sections we list some of the more relevant options that you may want to use.

For a Debug build

Create a Debug build to troubleshoot crashes in FreeCAD. Beware that with this build the Sketcher becomes very slow with complex sketches.

cmake -DCMAKE_BUILD_TYPE=Debug ../freecad-source

For a Release build

Create a Release build to test code that doesn't crash. A Release build will run much faster than a Debug build.

cmake -DCMAKE_BUILD_TYPE=Release ../freecad-source

Building against Python 3 and Qt5

By default, FreeCAD builds for Python 2 and Qt4. Since these two packages are obsolete, it is better to build for Python 3 and Qt5.

In a modern Linux distribution you only need to provide two variables specifying the use of Qt5, and the path to the Python interpreter.

cmake -DBUILD_QT5=ON -DPYTHON_EXECUTABLE=/usr/bin/python3 ../freecad-source

Building for a specific Python version

If the default python executable in your system is a symbolic link to Python 2, cmake will try to configure FreeCAD for this version. You can choose another version of Python by giving the path to a specific executable:

cmake -DPYTHON_EXECUTABLE=/usr/bin/python3 ../freecad-source

If that doesn't work, you may have to define additional variables pointing to the desired Python libraries and include directories:

cmake -DPYTHON_EXECUTABLE=/usr/bin/python3.6 \
    -DPYTHON_INCLUDE_DIR=/usr/include/python3.6m \
    -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.6m.so \
    -DPYTHON_PACKAGES_PATH=/usr/lib/python3.6/site-packages/ \
    ../freecad-source

It is possible to have several independent versions of Python in the same system, so the locations and version numbers of your Python files will depend on your particular Linux distribution. Use python3 -V to display the version of Python that you are using currently; only the first two numbers are necessary; for example, if the result is Python 3.6.8, you need to specify the directories that relate to the 3.6 version. If you don't know the right directories, try searching for them with the locate command.

locate python3.6

You may use python3 -m site in a terminal to determine the site-packages directory, or dist-packages for Debian systems.

Building with Qt Creator against Python 3 and Qt5

To compile in Qt Creator add the appropriate variables to the bottom of Projects → Manage Kits → Kits → Default (or your kit) → CMake Configuration. Again, specify the correct paths and Python version that you want to use.

PYTHON_EXECUTABLE=/usr/bin/python3.7
PYTHON_INCLUDE_DIR=/usr/include/python3.7m
PYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.7m.so
PYTHON_PACKAGES_PATH=/usr/lib/python3.7/site-packages
BUILD_QT5=ON

Go to Projects → Run → Run Configuration and choose FreeCADMain to compile the graphical version of FreeCAD, or FreeCADMainCMD to compile only the command line version.

Qt designer plugin

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

Go into an auxiliary directory of the source code, the run qmake with the indicated project file to create a Makefile; then run make to compile the plugin.

cd freecad-source/src/Tools/plugins/widget
qmake plugin.pro
make

If you are compiling for Qt5, make sure the qmake binary is the one for this version, so that the resulting Makefile contains the necessary information for Qt5.

cd freecad-source/src/Tools/plugins/widget
$QT_DIR/bin/qmake plugin.pro
make

where $QT_DIR is the directory that stores Qt binary libraries, for example, /usr/lib/x86_64-linux-gnu/qt5.

The library created is libFreeCAD_widgets.so, which needs to be copied to $QT_DIR/plugins/designer.

sudo cp libFreeCAD_widgets.so $QT_DIR/plugins/designer

External or internal Pivy

Previously, a version of Pivy was included in the source code of FreeCAD (internal). If you wanted to use your system's copy of Pivy (external), you needed to use -DFREECAD_USE_EXTERNAL_PIVY=1.

Using external Pivy became the default during development of FreeCAD 0.16, therefore this option does not need to be set manually anymore.

Doxygen documentation

If you have Doxygen installed you can build the source code documentation. See source documentation for instructions.

Additional documentation

The source code of FreeCAD is very extensive, and with CMake it's possible to configure many options. Learning to use CMake fully may be useful to choose the right options for your particular needs.

Making a debian package

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

sudo apt install dh-make devscripts lintian

Go to the FreeCAD directory and call

debuild

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

lintian freecad-package.deb

Updating the source code

The CMake system allows you to intelligently update the source code, and only recompile what has changed, making subsequent compilations faster.

Move to the location where the FreeCAD source code was first downloaded, and pull the new code:

cd freecad-source
git pull

Then move into the build directory where the code was compiled initially, and run cmake specifying the present directory (denoted by a dot); then trigger the re-compilation with make.

cd ../freecad-build
cmake .
make -j$(nproc --ignore=2)

Troubleshooting

For 64 bit systems

When building FreeCAD for 64-bit there is a known issue with the OpenCASCADE (OCCT) 64-bit package. To get FreeCAD running properly you might need to run the configure script and set additional CXXFLAGS:

./configure CXXFLAGS="-D_OCC64"

For Debian based systems this option is not needed when using the pre-built OpenCASCADE packages because these ones set the proper CXXFLAGS internally.

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 freshly installed Linux distribution. The commands will ask for the root password for installation of packages and new online repositories. 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 distribution, please discuss it on the FreeCAD forum so we can incorporate it.

Ubuntu

These scripts provide a reliable way to install the correct set of dependencies required to build and run FreeCAD on Ubuntu. They make use of the Ubuntu personal package archives (PPA), and should work on any version of Ubuntu targeted by the PPA. The freecad-daily PPA targets recent versions of Ubuntu, while the freecad-stable PPA targets officially supported versions of Ubuntu.

This script installs the daily compiled snapshot of FreeCAD and its dependencies. It adds the daily repository, gets the dependencies to build this version, and installs the required packages. Afterwards it proceeds to pull the source code into a particular directory, creates a build directory and changes into it, configures the compilation environment with cmake, and finally builds the entire program with make. Save the script to a file, make it executable, and run it, but don't use sudo; superuser privileges will be asked only for selected commands.

#!/bin/sh
sudo add-apt-repository --enable-source ppa:freecad-maintainers/freecad-daily && sudo apt-get update
sudo apt-get build-dep freecad-daily
sudo apt-get install freecad-daily

git clone https://github.com/FreeCAD/FreeCAD.git freecad-source
mkdir freecad-build
cd freecad-build
cmake -DBUILD_QT5=ON -DPYTHON_EXECUTABLE=/usr/bin/python3 ../freecad-source
make -j$(nproc --ignore=2)

If you wish, you can uninstall the pre-compiled version of FreeCAD (freecad-daily) while leaving the dependencies in place, however, leaving this package installed will allow the package manager to keep its dependencies up to date as well; this is mostly useful if you intend to follow the development of FreeCAD, and constantly update and compile the sources from the Git repository.

The previous script assumes that you want to compile the latest version of FreeCAD, so you are using the "daily" repository to get the dependencies. However, you can instead get the build dependencies of the "stable" version for your current Ubuntu release. If this is the case, replace the top part of the previous script with the following instructions. For Ubuntu 12.04, omit --enable-source from the command.

#!/bin/sh
sudo add-apt-repository --enable-source ppa:freecad-maintainers/freecad-stable && sudo apt-get update
sudo apt-get build-dep freecad
sudo apt-get install freecad

Once you install the freecad package from the freecad-stable repository, it will supersede the FreeCAD executable that is available from the Universe Ubuntu repository. The executable will be named simply freecad, and not freecad-stable.

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

# install needed packages for development
sudo zypper install 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 git swig
 
# create new dir, and go into it
mkdir FreeCAD-Compiled 
cd FreeCAD-Compiled
 
# get the source
git clone https://github.com/FreeCAD/FreeCAD.git free-cad
 
# Now you will have subfolder in this location called free-cad. It contains the source
 
# make another dir for compilation, and go into it
mkdir FreeCAD-Build1
cd FreeCAD-Build1 
 
# build configuration 
cmake ../free-cad
 
# build FreeCAD
make
 
# test FreeCAD
cd bin
./FreeCAD -t 0

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

# go into free-cad dir created earlier
cd free-cad
 
# pull
git pull
 
# get back to previous dir
cd ..
 
# Now repeat last few steps from before.
 
# make another dir for compilation, and go into it
mkdir FreeCAD-Build2
cd FreeCAD-Build2
 
# build configuration 
cmake ../free-cad
 
# build FreeCAD
# Note: to speed up build use all CPU cores: make -j$(nproc)
make
 
# test FreeCAD
cd bin
./FreeCAD -t 0

Debian Squeeze

# get the needed tools and libs
sudo apt-get install build-essential python libcoin60-dev libsoqt4-dev \
libxerces-c2-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 \
libqt4-dev qt4-dev-tools python2.5-dev \
libsimage-dev libopencascade-dev \
libsoqt4-dev libode-dev subversion cmake libeigen2-dev python-pivy \
libtool autotools-dev automake gfortran
 
# checkout the latest source
git clone https://github.com/FreeCAD/FreeCAD.git freecad
 
# go to source dir
cd freecad
 
# build configuration 
cmake .
 
# build FreeCAD
# Note: to speed up build use all CPU cores: make -j$(nproc)
make
 
# test FreeCAD
cd bin
./FreeCAD -t 0

Fedora 27/28/29

Posted by user [PrzemoF] in the forum.

#!/bin/bash

ARCH=$(arch)

MAIN_DIR=FreeCAD
BUILD_DIR=build

#FEDORA_VERSION=27
#FEDORA_VERSION=28
FEDORA_VERSION=29

PACKAGES="gcc cmake gcc-c++ boost-devel zlib-devel swig eigen3 qt-devel \
shiboken shiboken-devel pyside-tools python-pyside python-pyside-devel xerces-c \
xerces-c-devel OCE-devel smesh graphviz python-pivy python-matplotlib tbb-devel \
 freeimage-devel Coin3 Coin3-devel med-devel vtk-devel"

FEDORA_29_PACKAGES="boost-python2 boost-python3 boost-python2-devel boost-python3-devel"

if [ "$FEDORA_VERSION" = "29" ]; then
    PACKAGES="$PACKAGES $FEDORA_29_PACKAGES"
fi

echo "Installing packages required to build FreeCAD"
sudo dnf -y install $PACKAGES
cd ~
mkdir $MAIN_DIR || { echo "~/$MAIN_DIR already exist. Quitting.."; exit; }
cd $MAIN_DIR
git clone https://github.com/FreeCAD/FreeCAD.git
mkdir $BUILD_DIR || { echo "~/$BUILD_DIR already exist. Quitting.."; exit; }
cd $BUILD_DIR
cmake ../FreeCAD 
make -j$(nproc)

Arch using AUR

Arch User Repository (AUR) is a collection user made recipes to build packages which are not officially supported by distribution maintainers / community. They are usually safe. You can see who maintain the package and for how long he did. It is recommended to check construction files. Also non open source software are available in this area even if maintained by the official owning company.

Prerequisite : git

Steps :

  1. Open a terminal. Optionally create a directory eg. mkdir git. Optionally change directory eg. cd git.
  2. Clone the AUR repository : git clone http://aur.archlinux.org/packages/freecad-git
  3. Enter AUR repository folder : cd freecad-git
  4. Compile using Arch makepkg : makepkg -s. The -s or --syncdeps flag will also install required dependencies.
  5. Install created package : makepkg --install or double click on the pkgname-pkgver.pkg.tar.xz inside your file browser.

To update FreeCAD to latest build just repeat from step 3. Update AUR repo when there is some breaking change in the recipe or new features using git checkout -f inside the folder.