Compiling ITK on Windows
Contents
Install required software
Python 2.5 - http://www.python.org/ftp/python/2.5.2/python-2.5.2.msi
ITK - http://www.itk.org/ITK/resources/software.html.
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
CableSwig-ITK - http://www.itk.org/ITK/resources/software.html.
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.
CMake - http://www.cmake.org/cmake/resources/software.html.
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
Open the file ITK/Wrapping/CSwig/CommonA/wrap_itkLevelSet.cxx in a text editor
Notice the typedefs in the namespace _LSN_. Copy these typedef lines from namespace _LSN_{} into namespace wrappers{}, which is found below
- Save and close the file
Running CMake
- Run CMake.
Set the Where is the source code directory to the ITK folder
Set the Where to build the binaries directory to the binaries folder created earlier
Enable the Show Advanced Values checkbox
Click the Configure button once.
A 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
Click the Configure button once more and wait for it to complete. This will take about 5 minutes.
- Find and set the following four options:
BUILD_EXAMPLES
OFF
BUILD_SHARED_LIBS
ON
BUILD_TESTING
OFF
ITK_CSWIG_PYTHON
ON
Click the Configure button once more and wait for it to complete. Just click Cancel if CMake shows a warning about versions.
Click the Configure button once last time. Then click OK to finish and exit. Again, just click Cancel for any warnings.
Patches and Workarounds
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
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
Copy the file C:\msys\1.0\mingw\bin\mingwm10.dll into the ITK\binaries\bin folder
Place this file in the ITK\binaries\bin folder also: ITK.py
- Run MSYS by clicking on its shortcut on the desktop.
- 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
- 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.
- Please do this step carefully! Do these four steps for each of the three files listed below:
Search for the following text: --minor-image-version,10
Right after that text, enter the following (best to copy and paste - note the comma): ,--allow-multiple-definition
So that should now look like this: --minor-image-version,10,--allow-multiple-definition
- 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!)
- Start up a MSYS terminal
Change working directory to the ITK/binaries folder
Run make. This will take a couple of hours, maybe 2-3 hours.
Test ITK
Save the following two files into a folder: dm_test.py, attachment:dm_test.bmp
Run dm_test.py
When this completes, you should have two additional image files DanielssonDistanceMapImageFilterOutput1.png and DanielssonDistanceMapImageFilterOutput1.png that look like the following:
