} BuildingITK-SNAP
ITK-SNAP Logo

Latest News:
12/09/24: ITK-SNAP 4.2.2 has been released!

Building ITK-SNAP

This page describes how to build ITK-SNAP from source. The procedure is roughly the same for all supported platforms (Win32, MacOS, Linux), but there are subtle differences. This page gives the general outline of the build process, not a step-by-step walkthrough.

Prerequisites

Development Tools
In order to build ITK-SNAP, you need a C++ compiler for your platform. You also need Git. For Win32, we recommend Visual C++ Express Edition. You will also need an installation of CMake, a multi-platform build system. For MacOS, you need to obtain XCode and XCode command line tools using the App Store application.
C++ Libraries
You will need to download and build several C++ libraries to build ITK-SNAP. They are ITK, VTK, as well as Qt (ITK-SNAP versions prior to 3.0 used the FLTK toolkit instead of Qt). The table below summarizes the version of each tool that you need for respective versions of ITK-SNAP. Other combinations of versions may work as well, but these are the versions that we test against.
ITK-SNAP versionGIT branchCMake versionITK versionVTK versionFLTK or Qt version
1.8.0 and later 2.4.63.85.2FLTK 1.1.9
1.9.x and later 2.6.43.85.2FLTK 1.1.9
2.1.4 and later 2.6.43.205.61FLTK 1.3.x-r7710
2.3.0 and later 2.8.93.205.61FLTK 1.3
2.4.0 and laterrel_2.42.8.94.25.61FLTK 1.3
3.0.0 and laterrel_3.02.8.94.25.8Qt 4.8.2
3.2.0 and laterrel_3.22.8.124.5.26.1.0Qt 5.3.0
3.4.0 and laterrel_3.42.8.124.5.26.1.0Qt 5.4.0 or Qt 4.8.6 (with SNAP_USE_QT4)
3.6.0 and laterrel_3.62.8.124.8.26.3.0Qt 5.6.0 or Qt 4.8.6 (with SNAP_USE_QT4)
3.8.0 and laterrel_3.82.8.124.12.26.3.0Qt 5.6.0 or Qt 4.8.6 (with SNAP_USE_QT4)
Current developmentmaster3.225.2.19.1.0Qt 6.2.2
We recommend downloading CMake binaries (installers are available for MacOS and Win32) and building ITK, VTK and FLTK from source using CMake. The process for building ITK using CMake is described really well in the ITK Software Guide. Building VTK is similar. For Qt, we suggest downloading the prebuilt binaries for your system, if available.

Directory Structure

One important thing to keep in mind when using CMake is that source directories (where C++ code is) and build directories (where the C++ compiler stores the binary/library files) should be kept separate. On Linux and MacOS (but not on Win32, when using MS Visual C++), you may have multiple build directories, e.g., one for debugging and one for release-level, optimized binaries. A nice way to organize the directory structure is as follows.

itk/
itk/itk-5.2.1/itk/               <- ITK source tree
itk/itk-5.2.1/gcc64rel
vtk
vtk/vtk-9.1.0/vtk/               <- VTK source tree
vtk/vtk-9.1.0/gcc64rel/
itksnap/
itksnap/itksnap                  <- ITK-SNAP source tree 
itksnap/gcc64rel

Hints for Building Required Libraries

ITK 5.x
  • Set the flag Module_MorphologicalContourInterpolation to TRUE
VTK 9.x
  • Add a variable CMAKE_PREFIX_PATH and make it point to the location of the CMake modules in the Qt installation, e.g., C:/Qt/6.2.2/msvc2019_x64/lib/cmake on Windows.
  • Set VTK_GROUP_ENABLE_Qt to YES
  • Set VTK_MODULE_ENABLE_VTK_GUISupportQtQuick to NO
  • Set VTK_MODULE_ENABLE_VTK_GUISupportQtSQL to NO
  • Set VTK_REQUIRED_OBJCXX_FLAGS to an empty string
Qt
If you have to build Qt 4.7 or later from source, here are some hints. To reduce build time, you can use the following options to the configure script. The argument to --prefix should be the location where you want to install Qt. These instructions have not been tested with Qt 5.
./configure --prefix=/home/pauly/tk/Qt/qt-4.8.2 -no-webkit -fast -nomake demos -nomake tools \
                  -nomake examples -no-multimedia -no-phonon -no-qt3support -opensource
make
make install

Building ITK-SNAP

Once you've built ITK, VTK and FLTK using CMake, building ITK-SNAP is straightforward. When you run CMake, you will have to tell it where ITK, VTK, and Qt are located.

  • To help CMake find Qt version 5.0 or later, you have to manually add a CMake cache entry CMAKE_PREFIX_PATH which points to the location of the CMake modules in the Qt installation. For example, on Windows, this may be C:/Qt/6.2.2/msvc2019_x64/lib/cmake. Use the Add Entry button in the CMake GUI to do this.
  • For ITK and VTK, the CMake GUI will ask you for the location of their binary directory. In the directory structure above, you would set ITK_DIR to ..../itk/itk-4.5.2/gcc64rel and similar for VTK_DIR.

An example of the CMake GUI after configuration is shown below.

(:thumb win32cmake.png width=360:)

Once you've 'Configured' and 'Generated' in CMake, perform the build and you should have an executable ready to run. You can also build the package target (using the C++ IDE or on command line using make package) to generate an installer for your system. This is recommended if your ITK-SNAP binary complains about missing shared libraries.

Troubleshooting - All Platforms

  • You may encounter errors with PNG, JPEG and TIFF libraries. In my experience, the best way to avoid these errors is not to mess with ITK_USE_SYSTEM_PNG, VTK_USE_SYSTEM_PNG and other such flags. I have never had to change the default options to ITK, VTK and FLTK when building with CMake. There are some threads on the users' list and developers' list dealing with this issue.
  • If you are stuck, take a look at the compilation settings used on our nightly build machines. You can see what CMake parameters were needed on different operating systems. Specifically, look at the CACHE_ADD and ENV_ADD commands in the scripts in the sites subdirectory. These correspond to options specified in CMake and environment variables used when running Cmake.
  • If you are using ITKv5, you may encounter "itkVectorResampleImageFilter.h: No such file or directory". Download an older version of ITK and use this library to build ITK-Snap (works with ITK 4.13.2). Same with VTKv8 (unable to find VTKObject.h): download an older version of VTK and use this library to build ITK-Snap (works with VTK 7.1.1).

Troubleshooting - MacOS

  • If you are using GCC and it complains with "library not found for -lSM" or "library not found for -lICE", it means that it can't find the library in the default location. These libraries are located in /usr/X11R6/lib/, but the linker does not know about that directory. One easy hack is to create a link to these files in /usr/lib
sudo ln -s /usr/X11R6/lib/libSM* /usr/lib
sudo ln -s /usr/X11R6/lib/libICE* /usr/lib
  • With XCode > 4.3.2, the new default compiler clang is not compatible with ITK version 3. However, it is easy to tell CMake to use the older GCC compiler using the environment variables CC and CXX.
CC=/usr/bin/gcc
CXX=/usr/bin/g++
export CC CXX
ccmake ...

Cross-Compiling on Linux

  • It is possible to compile a 32 bit binary on 64 bit linux. The general rule is to set the environment vars CFLAGS and CXXFLAGS to -m32 before running cmake in a clean directory. To build FLTK, you also have to call its configure script with the option '--x-libraries=/usr/lib
Page last modified on June 07, 2022, at 05:07 PM

    SourceForge.net Logo   Valid XHTML 1.0 Transitional