Compile on MinGW

This guide will walk through the steps necessary to build FreeCAD on Windows using the MSYS2/MinGW environment. Basic familiarity with Bash shell commands will be useful for understanding what each step does, but following the guide by rote should result in a working build even if you don't understand exactly what you did to get it.

Before you start
Download and install MSYS2 if you have not already. To ensure your MSYS2 system is up-to-date, consider running: pacman -Syu and then relaunching and running pacman -Su before proceeding.

Install basic development tools
In all of the following steps, when prompted by MSYS2's shell, accept the default installations of everything by pressing "Enter" when asked.

First, install the mingw-w64 GCC toolchain: pacman -S --needed base-devel mingw-w64-x86_64-toolchain This will probably take several minutes to complete, as the compiler toolchain is quite large.

Install cmake: pacman -S cmake

Install git: pacman -S git

Either ensure that your PATH contains the path to the mingw-w64 toolchain: export PATH=$PATH:/mingw64/bin or launch MSYS2 MinGW 64-bit from your MSYS2 installation.

Check out the FreeCAD sources
To get the FreeCAD source code, clone it from the main git repository: git clone https://github.com/FreeCAD/FreeCAD

If you do not want to compile the latest HEAD, once you have the source you can check out a specific tag: cd FreeCAD git checkout tags/0.19.2 -b releases/FreeCAD-0-19

Or a specific pull request (in this example, PR 1234): cd FreeCAD git fetch origin pull/1234/head:pr/1234 git checkout pr/1234

Install required libraries
FreeCAD depends on many 3rd-party libraries for its functionality. They may be installed individually, or as a single unified command. Updating this list is the current ongoing work of this documentation: to help, repeatedly run the cmake command from the next section, and install whatever the next package is that it errors on. As of this writing there is a problem with the pacman-installed OpenCASCADE package.


 * mingw-w64-x86_64-opencascade

To resolve the current (9/11/2021) problem with the OpenCASCADE installation, it is necessary to modify the installed cMake configuration files for the library. In the files /mingw64/lib/cmake/opencascade/*-release.cmake, remove all occurrences of the string \${OCCT_INSTALL_BIN_LETTER} (Note the leading backslash -- that character must be removed along with the variable reference).

Now, install the following dependencies using pacman:


 * mingw-w64-x86_64-xerces-c
 * mingw-w64-x86_64-qt5

Build FreeCAD
Make a directory for the build: note this is typically not a subdirectory of the source directory (it is often useful to be abloe to delete either the source or the build directory independently). mkdir FreeCAD-build cd FreeCAD-build

Run cMake: cmake ../FreeCAD