Building ITK with the Mingw-w64 Compiler

ITK Background

The Insight Segmentation and Registration Toolkit (ITK) is a cross-platform, open-source framework that supports the development of image segmentation and registration applications with an extensive suite of software tools. This suite includes leading-edge algorithms for analyzing multidimensional data.

ITK is mainly implemented in C++, and it uses the CMake build environment to manage the process of generating and compiling projects in a platform-independent way. In addition, ITK can be wrapped for high-level programming languages such as Python with an integrated, automatic wrapping system. This system is based on Simplified Wrapper and Interface Generator (SWIG) for rapid prototyping and fast exploration.

About Mingw-w64

Mingw-w64 is forked from the MinGW project. Mingw-w64 supports a complete run-time environment for the GNU Compiler Collection (GCC) on Windows 64-bit and 32-bit operating systems. Mingw-w64 also provides more complete Win32 application programming interfaces (APIs) including Windows 7/8/8.1 APIs, POSIX threads, and GCC multi-lib tool chains. Additionally, Mingw-w64 is used by several other projects such as Fedora MinGW, the R Project for Statistical Computing, and Qt. Consequently, Mingw-w64 compilers are widely applied.

Building ITK with Mingw-w64

In this blog post, we describe how to build ITK with the Mingw-w64 compiler.

Preparing Mingw-w64 compiler

The Mingw-w64 compiler can be download from the following Web page: http://mingw-w64.org/doku.php/download/mingw-builds.

Fig_1_Mingw-w64_Web

Once you have clicked on “Sourceforge” in the webpage, the latest version installer of the Mingw-w64 compiler will automatically download.

After you have downloaded the installer of “mingw-w64-install.exe,” simply navigate to the download location on your computer, double-click the file, and press “Yes,”  when the dialog box pops up.

Fig_Mingw-w64_PopUP

Press “Next” to install the Mingw-w64 compiler on your Windows system.

Fig_Mingw-w64_PopUP_2

Select i686 or x86_64 for the architecture; posix or Win32 for the threads; and dwarf, seh, or sjlj for the exception for installing the Mingw-w64 compiler. We recommend that you install the latest version of the Mingw-w64 64-bit (x86_64) compilers. Then, click “Next” to continue.

Fig_Mingw-w64_PopUP_3_

Define your destination folder for the Mingw-w64 compiler. Then, press “Next.”

Fig_Mingw-w64_PopUP_4_

You have completed the installation process; click “Finish.”

Fig_Mingw-w64_PopUP_2

Now, you have a Mingw-w64 compiler on your Windows system.

Configuring and Building ITK with Mingw-w64 compiler

We will use CMake (the GUI version) and the Ninja build system for configuring and building ITK source code.  

Preparing CMake

You can download a windows installer of CMake (cmake-X.X.X-win32-x86,msi) from the CMake download page. Follow the instructions provided on the CMake installation page for downloading and installing the software.

Note: Add CMake to the system path.

Fig_CMake_Install

Preparing the Ninja Build System

The Ninja build system has been designed and developed for high speeds. CMake supports generating Ninja files on Windows, Linux, and Mac OS X.

Download the Ninja binary for Windows from the Ninja homepage, extract the zip file (ninja-win.zip), and copy the executable file in your destination folder. In our case, the path of the Ninja build system is “C:\Program Files\ninja-win.”

Then, add the destination folder of Ninja to the system path with the following steps:

  1. On the desktop, right-click on the computer icon.
  2. Choose “Properties” from the context menu.
  3. Click on the “Advanced System” settings link.
  4. Click “Environment Variables.”
  5. In the System Variables section, find the PATH environment variable, and select it.
  6. Click “Edit.”
  7. In the Edit System Variable window, insert the path of your Ninja directory. 
  8. Click “OK.”
  9. Close all remaining windows by clicking “OK.”

Fig_Ninja_System_Path

Getting ITK Source Code

You can download ITK source code from the ITK download page or the ITK Git repository.

For more detailed information, please refer to chapter 1.3 of “ITK Software Guide: Introduction and Development Guidelines,” and follow the instructions supported by the ITK/Git/Download webpage.

Configuring ITK with CMake and the Mingw-w64 Compiler

Open the terminal for the installed Mingw-w64 compiler by selecting “Run terminal.”

Fig_Run_Mingw_w64_Terminal

In the terminal, run “cmake-gui” to configure the ITK source code.

Fig_Run_CMAKE_GUI

Define the path of the ITK source code and a binary directory in the respective “Where is the source code” and “Where to build the binaries” edit boxes. Then, press “Configure.”

Fig_CMake_Configure

If your binary directory does not exist, press “Yes” to create a folder.

Fig_CMake_PopUp

Select “Ninja” as a generator to build the ITK source code.

Fig_CMake_Select_Generator

For more information about configuring ITK, please see chapter 2.1 of “ITK Software Guide: Introduction and Development Guidelines.”

Once the configuration is done, press “Generate” to create Ninja files for compiling the ITK source code.

Fig_CMake_Generate

After the generation is complete, go to your binary directory in the terminal. Then, run the Ninja build system to compile the ITK source code.

Fig_Run_Mingw_w64_Terminal_2

Welcome to ITK! For more information about getting started with ITK, please check chapter 2.2 of “ITK Software Guide: Introduction and Development Guidelines.”

Questions or comments are always welcome!