Compiling ITK on Windows

Install required software

  1. Python 2.5 –

  2. MinGW –

    • First install MSYS, and say “no” to it’s post installation.

    • Then install MSYS DTK.

    • Then do a full install of MinGW to c:\msys\1.0\mingw.

  3. ITK –

    • The latest version was ITK 3.10.2 at the time of this writing.

    • Extract contents of zip package. Rename the extracted folder from InsightToolkit-3.10.2 to ITK.

    • In the new ITK folder, make another folder called binaries

  4. CableSwig-ITK –

    • Direct download link of corresponding version: CableSwig-ITK 3.10.

    • Extract contents of zip package. Rename the extracted folder from CableSwig-ITK-3.10.0 to just CableSwig. Move this folder into ITK\Utilities.

  5. CMake –

    • The latest version was CMake 2.6.2 at the time of this writing.

    • Download the Windows installer and install CMake

Setup build system using CMake

Patch ITK LevelSet CSWIG wrapper

  1. Open the file ITK/Wrapping/CSwig/CommonA/wrap_itkLevelSet.cxx in a text editor

  2. Notice the typedefs in the namespace _LSN_. Copy these typedef lines from namespace _LSN_{} into namespace wrappers{}, which is found below

  3. Save and close the file

Running CMake

  1. Run CMake.
  2. Set the Where is the source code directory to the ITK folder

  3. Set the Where to build the binaries directory to the binaries folder created earlier

  4. Enable the Show Advanced Values checkbox

  5. Click the Configure button once.

  6. Select Generator prompt should pop up.

    • Select MSYS Makefiles from the drop-down list and click OK.

    • CMake will probably alert that your C compiler: "gcc.exe" was not found. Ignore this, and click Cancel to supress further messages.

    • In the list of options, find the CMAKE_CXX_COMPILER option. For that option, enter C:/msys/1.0/mingw/bin/g++.exe

    • Right below it, there should be the CMAKE_C_COMPILER option. For that one, enter C:/msys/1.0/mingw/bin/gcc.exe

  7. Click the Configure button once more and wait for it to complete. This will take about 5 minutes.

  8. Find and set the following four options:











  9. Click the Configure button once more and wait for it to complete. Just click Cancel if CMake shows a warning about versions.

  10. Click the Configure button once last time. Then click OK to finish and exit. Again, just click Cancel for any warnings.

Patches and Workarounds

  1. Edit C:\msys\1.0\msys.bat to get a compatible shell

    • Open the file in a text editor
    • Find the line that says if EXIST rxvt.exe goto startrxvt

    • Comment out that line by inserting a # at the beginning of the line

    • Save and close the file
  2. Open the file ITK\binaries\Makefile in a text editor

    • Find the all make target by doing a search for all:. Note: this might also find install:, but we want all:

    • Remove the dependency for all by deleting the text cmake_check_build_system from the dependency list of all:

    • Save and close the file
  3. Copy the file C:\msys\1.0\mingw\bin\mingwm10.dll into the ITK\binaries\bin folder

  4. Place this file in the ITK\binaries\bin folder also:

  5. Run MSYS by clicking on its shortcut on the desktop.
  6. Change working directory to the ITK folder by using a command like the following (might be a little different depending on where you put the ITK folder):
    • cd /c/Documents and Settings/ajain/Desktop/ITK


  7. Then run the following command (note the grave accents)
    • rm `find Utilities/CableSwig/GCC_XML/Support/GCC -name gthr-default.h`


    • What this does is removes all instances of the threads-related header file gthr-default.h included in CableSwig. This is because we want to use the one included in MinGW. Otherwise, this causes a problem during the compilation process.

  8. Please do this step carefully! Do these four steps for each of the three files listed below:
    1. Search for the following text: --minor-image-version,10

    2. Right after that text, enter the following (best to copy and paste – note the comma): ,--allow-multiple-definition

    3. So that should now look like this: --minor-image-version,10,--allow-multiple-definition

    4. Save and close the file
    • (1) ITK\binaries\Wrapping\CSwig\CommonB\CMakeFiles\_ITKCommonBPython.dir\build.make 
      (2) ITK\binaries\Wrapping\CSwig\Numerics\CMakeFiles\_ITKNumericsPython.dir\build.make
      (3) ITK\binaries\Wrapping\CSwig\Algorithms\CMakeFiles\_ITKAlgorithmsPython.dir\build.make


Building ITK (finally!)

  1. Start up a MSYS terminal
  2. Change working directory to the ITK/binaries folder

  3. Run make. This will take a couple of hours, maybe 2-3 hours.

Test ITK

  1. Save the following two files into a folder: dm_test.pydm_test.bmp

  2. Run

  3. When this completes, you should have two additional image files DanielssonDistanceMapImageFilterOutput1.png and DanielssonDistanceMapImageFilterOutput1.png that look like the following: