MITK MinGW Compatibility

(Redirected from MinGW Instructions)
Jump to navigation Jump to search
 This site is out-dated! We do not support MinGW anymore.

Compiling MITK with MinGW on Windows

MITK now supports MinGW (gcc 4.4.0), which means you can use gcc under Windows to compile native libraries and executables. In order to use MinGW as a toolchain, all dependent libraries (Qt, ITK, and VTK) must be compiled with gcc too. Read Build Requirements for general information.

The easy way

To make your life simpler, you should install a Qt SDK based on Qt 4.6 (if you do not want to use Qt, see the not so easy way below). This gives you a MinGW compiled Qt 4.6, Qt Creator, and MinGW itself. For convenience, you should add the "bin" folder of the MinGW installation in your Qt directory to the PATH environment variable.

To further simplify things, you should set-up a MSYS environment (download 1.0.11) for the compilation and installation process (you will need it for MITK later on anyway). We will refer to "C:\msys\1.0" as your MSYS installation directory.

Start by building ITK and VTK.


Get ITK (tested for version 3.16) and configure it with CMake:

  • Select the "MSYS Makefiles" generator
  • Set CMAKE_BUILD_TYPE to "Release" (or "Debug", if you want to debug ITK)
  • Uncheck either CMAKE_USE_PTHREADS or CMAKE_USE_WIN32_THREADS (tested only with CMAKE_USE_WIN32_THREADS set to "ON")
  • Set CMAKE_INSTALL_PREFIX to "C:/msys/1.0/local"
  • Change other options as you see fit

Run configure and generate to generate MSYS makefiles. Supposing that your ITK binary tree is located in "C:\toolkits\itk-3.16_release", you can now open a MSYS shell and execute:

<syntaxhighlight lang="bash"> cd /c/toolkits/itk-3.16_release make -j4 make install </syntaxhighlight>

This will copy the ITK libraries and header files to the path specified in CMAKE_INSTALL_PREFIX. Due to a bug in the ITK CMake install scripts, you have to move C:\msys\1.0\local\lib\InsightToolkit\libitksys.dll to C:\msys\1.0\local\bin by hand. You may now delete your ITK binary (and source) tree.


VTK 5.4.2 contains a buggy freetype library, so you have to compile it yourself first.

  • Get freetype 2.3.11 or newer (only tested with 2.3.11) and unpack it in a temporary directory, for example c:\tmp
  • Open a MSYS shell, and type:

<syntaxhighlight lang="bash"> cd /c/tmp/freetype-2.3.11 ./configure make -j4 make install </syntaxhighlight>

This installs the FreeType2 libraries and headers into your MSYS environment.

Next, get VTK 5.4.2 and configure it with CMake:

  • Select the "MSYS Makefiles" generator
  • Set CMAKE_BUILD_TYPE to "Release" (or "Debug", if you want to debug VTK)
  • Uncheck either CMAKE_USE_PTHREADS or CMAKE_USE_WIN32_THREADS (tested only with CMAKE_USE_WIN32_THREADS set to "ON")
  • Uncheck VTK_USE_VIDEO4WINDOWS (MinGW does not provide headers for it)
  • (optional) Uncheck VTK_USE_GEOVIS, VTK_USE_INFOVIS, and VTK_USE_VIEWS (not needed for MITK)
  • Set CMAKE_INSTALL_PREFIX to "C:/msys/1.0/local"
  • Change other options as you see fit

Run configure, set the DESIRED_QT_VERSION variable to "4" and configure freeetype:

  • FREETYPE_INCLUDE_DIR_freetype2 = "C:/msys/1.0/local/include/freetype2"
  • FREETYPE_INCLUDE_DIR_ft2build = "C:/msys/1.0/local/include"
  • FREETYPE_LIBRARY = "C:/msys/1.0/local/bin/freetype-6.dll"

Run configure until there are no new variables and generate MSYS makefiles. You can now open a MSYS shell and cd into your VTK binary directory. Due to another "bug" in the VTK CMake scripts, you also need to hint gcc at the include directories for freetype:

<syntaxhighlight lang="bash"> cd /c/toolkits/vtk5.4.2/ export CPLUS_INCLUDE_PATH=/usr/local/include:/usr/local/include/freetype2 make -j4 make install </syntaxhighlight>


Due to a buffer size limit of 8K for command line arguments in cmd.exe, MITK has to be build by using a build-system which uses a shell without this limitation. If you have not built ITK and VTK using MSYS, look above on how to obtain it. You don't need to put the bin folder of your MSYS installation into your PATH environment variable (this may have unwanted side-effects), just use the absolute path to MSYS make.exe if you are not inside a MSYS shell.

  • Select the "MSYS Makefiles" generator
  • If Qt has not been found, enter the path to qmake.exe in QT_QMAKE_EXECUTABLE (if you use the Qt SDK, it is located in your installation directory under qt/bin/qmake.exe)
  • Enter "Release" or "Debug" in CMAKE_BUILD_TYPE
  • Enter the path to your binary ITK and VTK directory in ITK_DIR and VTK_DIR
  • If you want to use the supplied application (ExtApp), enable specific bundles by checking any of the MITK_BUILD_org.mitk variables.

Run configure until there are no new variables and generate the MSYS makefiles. You can now open a MSYS shell, cd into your MITK binary directory and execute "make.exe -j4" (if you got 4 CPU cores).

Starting MITK applications If you start an MITK application (for example ExtApp), the library loader needs to know where to look for dependent libraries. You can set the PATH variable in a MSYS shell such that all libraries are found:

<syntaxhighlight lang="bash"> export PATH=$PATH:/C/Qt/2009.05/qt/bin:/usr/local/bin:/<mitk-binary-tree>/bin/BlueBerry/org.blueberry.osgi/bin /<mitk-binary-tree>/bin/ExtApp </syntaxhighlight>

The first path entry contains the Qt .dll files, the second contains the .dll files from ITK, FreeType, and VTK. The last entry points to a shared library needed for bootstrapping an MITK application.

For Qt Creator integration, see below.

MITK and Qt Creator

Qt Creator 1.3 does not yet support MSYS based CMake projects (watch this bug report for progress on this issue). Follow the points below to build MITK with Qt Creator.

If you want to develop your own project (bundle, shared library, etc.) which depends on MITK, you should place your source code outside of MITK (see for example How to create a new MITK Plug-in). You should be able to apply the steps below to your external project.

  • Import your MITK source project by choosing "Import of Makefile-based Project" after clicking on "File -> New File or Project...".
  • Set-up your project by choosing the CMake configured binary tree as build directory, and use the absolute path to your MSYS make.exe as make command.
  • Add additional build configurations for special targets like "ExtApp".
  • Create a new run configuration and add the paths to the bin directories of ITK, VTK, FreeType, Qt and org.blueberry.osgi (see "Starting MITK applications" in the preceding section).

This should enable you to develop MITK-based programs with Qt Creator.

The not so easy way

If you don't want to install the Qt SDK or don't want to use Qt at all, you have to install MinGW yourself. Create a new directory, for example C:\MinGW and unpack the following files from (or newer versions) into this directory:

  • GCC current release (tested with ggc-4.4.0):
    • Core bin and dll:
      • gcc-core-4.4.0-mingw32-bin.tar.gz
      • gcc-core-4.4.0-mingw32-dll.tar.gz
  • C++ bin and dll:
    • gcc-c++-4.4.0-mingw32-bin.tar.gz
    • gcc-c++-4.4.0-mingw32-dll.tar.gz
  • Gmp dll:
    • gmp-4.2.4-mingw32-dll.tar.gz
  • Mpfr dll:
    • mpfr-2.4.1-mingw32-dll.tar.gz
  • GNU Binutils current release bin
    • binutils-2.19.1-mingw32-bin.tar.gz
  • GNU Make current release bin
    • mingw32-make-3.81-2.tar.gz
  • MinGW API for MS-Windows current release
    • w32api-3.13-mingw32-dev.tar.gz
  • MinGW Runtime current release
    • mingw-runtime-3.14.tar.gz

For convenience, you should add "C:\MinGW\bin" to your PATH environment variable. Now proceed with compiling ITK, VTK and MITK as explained above.

Some random information

  • Qt 4.5.3 comes with a very old MinGW (gcc 3.4.2)
  • Qt 4.6 is compiled with a recent gcc (4.4.0)
  • The Qt SDK based on Qt 4.6 comes with MinGW, which can be used just fine
  • The MinGW automated installer is not up-to-date (it installs gcc 3.4.5). However, this is still too new to use with Qt 4.5.3 (the installer will refuse to work with the MinGW version installed via the automated installer).
  • ITK 3.14 and VTK 5.4.2 compile fine with MinGW from Qt 4.5.3
  • ITK 3.16 and VTK 5.4.2 compile with MinGW (gcc 4.4) from Qt Creator 1.3 RC (update: and above)
  • VTK svn (from 14.12.2009 onwards) contains freetype 2.3.11. This may make it obsolete to build freetype standalone.
  • Poco does not compile with MinGW from Qt 4.5.3 (the win32api headers are too old)
  • DCMTK 3.5.4 will not compile with MinGW (tested for gcc 4.4). You will need this patch Media:MinGW_Instructions$dcmtk-3.5.4-mingw.patch.
  • The mitkCore does not link to ITK due to multiple definitions of the same symbol present in libITKCommon.dll and libitkvnl.a (for ITK 3.14)
  • MITK links fine to ITK 3.16
  • MinGW libraries and executables seem to contain some debugging info even in release mode. CPack has an option CPACK_STRIP_FILES which strips the information from the files during packaging. One can also manually set the CMake variables CMAKE_EXE_LINKER_FLAGS_RELEASE and CMAKE_SHARED_LINKER_FLAGS_RELEASE to "-s" for ITK, VTK and MITK to strip the files during linking.
  • The CMake MinGW generator cannot be used on Windows for MITK. mingw32-make spawns calls to gcc via which has a command line buffer limit of 8k. This buffer size is easily exceeded in MITK by supplying a lot of include paths to gcc.
  • The only way right now to compile MITK with MinGW on Windows is to use MSYS and the MSYS make.exe. Use the CMake MSYS generator.
  • Qt Creator does not support the CMake MSYS generator yet. The project must be imported as a Makefile Project and set up by hand.
  • Calling ctest from within a MSYS shell leads to problems for BlueBerry tests. Usually, command line arguments are preceded by a "/" under Windows but for MSYS, it must be "//".

Cross-compiling MITK with MinGW on Fedora 11

  • ITK needs to be patched because of the use of a generated executable in a custom cmake command (or make your Linux start .exe files automagically with wine). Further, linking to the ITK libraries will result in "multiple definitions" errors for symbols being found in static ITK utility libraries and the shared ITK libraries (to which the static libraries have been linked before for ITK 3.14, resolved in 3.16).
  • VTK compiles fine when INFOVIS, GEOVIS, USE_VIEWS, etc. is disabled
  • MITK compiles and links against Qt, VTK and ITK within SVN Head