Documentation/4.5/Developers/Build Instructions

From Slicer Wiki
Jump to: navigation, search
Home < Documentation < 4.5 < Developers < Build Instructions


For the latest Slicer documentation, visit the read-the-docs.


PREREQUISITES


Consider reading platform specific requirements listed below.

Linux

  • CMake >= 3.x
  • Git >= 1.7.10
  • Svn >= 1.7
  • Qt 4.8.6. See details here (Note that any version >= Qt 4.7.4 can be used only for Ubuntu < 12.04)

Debian

  • Debian squeeze/wheezy/testing(jessie) users, start by pasting the following lines in a terminal
sudo apt-get install subversion git-core git-svn
sudo apt-get install make gcc g++ libX11-dev libXt-dev libgl1-mesa-dev libosmesa6-dev libglu1-mesa-dev libfontconfig-dev libxrender-dev libncurses5-dev
sudo apt-get install cmake
sudo apt-get install qt-sdk

Ubuntu

  • Ubuntu users, start by pasting the following lines in a terminal
sudo apt-get install subversion git-core git-svn
sudo apt-get install make gcc g++ libX11-dev libXt-dev libgl1-mesa-dev libglu1-mesa-dev libfontconfig-dev libxrender-dev libncurses5-dev


For Ubuntu < 12.04:

sudo apt-get install cmake # Only for Ubuntu < 12.04

For Ubuntu < 14.04.3:

sudo apt-get install libosmesa6-dev
  • NOTE: on Ubuntu 14.04.3 LTS, attempting to install libosmesa6-dev results in an error:
The following packages have unmet dependencies:
 libosmesa6-dev : Depends: libosmesa6 (= 10.1.3-0ubuntu0.4) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

See Bug 1424059.

Slicer compiles successfully without that package, but VTK_OPENGL_HAS_OSMESA is disabled.

For Ubuntu 12.04 and above: You *MUST download the standard CMake binary* from http://cmake.org/download because the distributed version of CMake cannot be used to build slicer. For example, on a 64-bit system, you will download the file cmake-X.Y.Z-Linux-x86_64.tar.gz associated with the latest stable version.

References:


For Ubuntu 12.04, 12.10, 13.04 and 13.10: Qt 4 >= 4.8.5 MUST be used. See reference below for more details.

cd ~/Support   # This is where we will build Qt and dependent libraries
 
# Keep track of our working directory
cwd=$(pwd)

# This will download, then build zlib and openssl in the current folder
rm -f get-and-build-openssl-for-slicer.sh
wget https://gist.githubusercontent.com/jcfr/9513568/raw/21f4e4cabca5ad03435ecc17ab546dab5e2c1a2f/get-and-build-openssl-for-slicer.sh
chmod u+x get-and-build-openssl-for-slicer.sh 
./get-and-build-openssl-for-slicer.sh 

# This will download Qt source in the current folder
wget http://packages.kitware.com/download/item/6175/qt-everywhere-opensource-src-4.8.6.tar.gz
md5=`md5sum ./qt-everywhere-opensource-src-4.8.6.tar.gz | awk '{ print $1 }'` &&
[ $md5 == "2edbe4d6c2eff33ef91732602f3518eb" ] || echo "MD5 mismatch. Problem downloading Qt"

# This will configure and build Qt in RELEASE against the zlib and openssl previously built
tar -xzvf qt-everywhere-opensource-src-4.8.6.tar.gz
mv qt-everywhere-opensource-src-4.8.6 qt-everywhere-opensource-release-src-4.8.6
mkdir qt-everywhere-opensource-release-build-4.8.6
cd qt-everywhere-opensource-release-src-4.8.6
./configure -prefix $cwd/qt-everywhere-opensource-release-build-4.8.6    \
                   -release \
                   -opensource -confirm-license \
                   -no-qt3support \
                   -webkit \
                   -nomake examples -nomake demos \
                   -openssl -I $cwd/openssl-1.0.1e/include   -L $cwd/openssl-1.0.1e \
&& make -j7 && make install

References:

  • Why Qt 4 >= 4.8.5 should be used on Ubuntu 12.04 and above ?

CentOS

  • CentOS user type:
yum install make gcc-c++ libX11-devel libXt-devel libXext-devel libGLU-devel mesa-libOSMesa-devel mesa-libGL-devel mesa-libGLU-devel ncurses


MacOSX

MacOSX 10.9.4 (Maverick):

(1) Make sure to install this update: http://support.apple.com/kb/DL1754

(2) Use CMake 3.0.1 - it is known to be working and is supported (if you want to use CMake already installed on your system, 2.8.12.2 is known to work on Mac OS X 10.9.5)

$ curl -O http://www.cmake.org/files/v2.8/cmake-2.8.11-Darwin64-universal.tar.gz
$ tar -xzvf cmake-2.8.11-Darwin64-universal.tar.gz --strip-components=1
$ CMake\ 2.8-11.app/Contents/bin/cmake --version
cmake version 2.8.11

Windows

  • CMake >= 3.0
  • Git >= 1.7.10
    • Note For convenience, you could update the PATH variable so that git can be automatically discovered when configuring Slicer. If not, you will have to specify the GIT_EXECUTABLE at configure time.
  • SlikSvn . If using TortoiseSVN (versions that support command line tools), make sure you install Command line tools (disabled by default)
  • NSIS (optional): Needed if packaging Slicer - Click here to download.
  • Qt 4.8.6 (for VS2008). See details here
    • Normally you should plan to build Qt from source to have complete control over the process. See one-liner build command
    • You may find that the unsigned binary downloads from this site are usable: http://sourceforge.net/projects/qt64ng/files/qt/x86-64/4.8.6/msvc2008/ (If you use .7z varaints extract them in the default location C:\Qt\ otherwise that installation will not be properly configured for use with CMake)
    • Details: Using the Qt Designer on Windows requires that the Slicer plugins are compiled in the same mode as Qt. If Qt was compiled in Release mode (default), Slicer would have to be compiled in Release mode as well. However if Qt is compiled in Debug mode only, Slicer has to be compiled in Debug too. When Qt is in "Release and Debug" mode only the Release version of Designer.exe is generated, Slicer would have to be compiled in Release. So for developers, the Debug mode is recommended.
    • For VS2012 Qt needs to be build from source. Build will fail, which can be fixed with this diff: https://gist.github.com/Vitallium/5220503 (read the comment too)
  • IDE
    • Tested/Recommended: Microsoft Visual Studio 9 2008 (Any edition). VS Express 2008 with SP1 direct link (functional as of Jan 11, 2014)
    • Experimental: The plan is to support Microsoft Visual Studio 2010 (Any edition). Note NOTE THAT EXPERIMENTAL MEANS THIS DOESN'T YET WORK :)
      • Make sure to build or install:
        • Qt 4.8
      • Make sure to install:
        • SP1. Click here to download SP1 and click here to understand the motivation.
        • SP1 Compiler update. Click here to download and here to understand the motivation.
    • Experimental (Visual Studio 2012): Use a desktop version such as Visual Studio 2012 Express for Windows Desktop and remember Visual Studio 2012 Update 2). Do not use Visual Studio Express 2012 for Windows 8. You must install Windows SDK, otherwise CMake will not even find the C compiler during configure. In CMake, choose Visual Studio 11 Win64 as generator.
    • Experimental (Visual Studio 2013 with Update 5, as of commit 7160260): Slicer compilation is successful, with some caveats. Steps:
      • CMake >= 3.3.1
      • Build Qt 4.8.7 with SSL support using qt-easy-build.
      • For Debug mode, disable Slicer_USE_SimpleITK in CMake.
    • Un-tested: Cygwin suite (building with cygwin gcc not supported, but the cygwin shell environment can be used to run git, svn, etc).






CHECKOUT slicer source files


Check out the code using git and configure the git svn bridge:

  1. While it is not enforced, we strongly recommend you to AVOID the use of SPACES for both the source directory and the build directory. We mean it.
  1. Clone the github repository

    cd MyProjects
    git clone git://github.com/Slicer/Slicer.git

    The Slicer directory is automatically created after cloning Slicer.

  2. Setup the development environment:

    cd Slicer
    ./Utilities/SetupForDevelopment.sh

    For more details see Development With Git.

    On Windows enter the commands above in to a bash shell, such as Git Bash (part of msysgit).

  3. Configure the git svn bridge to ensure the mapping with svn revision.

    cd Slicer
    git svn init http://svn.slicer.org/Slicer4/trunk
    git update-ref refs/remotes/git-svn refs/remotes/origin/master
    git checkout master
    git svn rebase
  4. If you plan to compile Slicer to develop your own extensions and test these extensions on Slicer releases, it is convenient to download the source code directly from SVN and specify the revision number corresponding to the release you want.
    svn co http://svn.slicer.org/Slicer4/trunk Slicer-r23774 -r 23774
    
     Release         SVN revision#
     4.4                 23774
     4.3.1               22599
     4.3.0               22408
    

    More corresponding SVN revision numbers can be found here and here








CONFIGURE and generate Slicer solution files

You can configure and generate Slicer solution files using either ccmake or cmake-gui.


Per-platform instructions

Windows

  • Recommended: cmake-gui
    • Set the build directory. For example: C:\Slicer-SuperBuild-Debug or C:\Slicer-SuperBuild-Release.
      • Because Windows doesn't support file path longer than 260 characters and has a maximum command line length, please make sure that the total path name of your Slicer-build directory is no longer than 50 characters (for example c:\work\Slicer\Slicer-SuperBuild (32 characters) is fine). In case of any build error, use very short directory names: C:\S4 for source directory, C:\S4D for debug build, C:\S4R for release build.
      • You cannot use the same build tree for both release or debug mode builds. If both build types are needed, then the same source directory can be used, but a separate build directory should be created and configured for each build type.
    • Select your compiler: Visual Studio 9 2008 Win64
    • Configure using default options. You may get a configuration error that QT_QMAKE_EXECUTABLE is not set, which is normal.
    • Verify that QT_QMAKE_EXECUTABLE variable is set correctly:
      • CMake may automatically detect an installed version of Qt, but you may want to use a custom built version of Qt (e.g. in Debug mode for use with the designer).
      • Set QT_QMAKE_EXECUTABLE to the path of the qmake.exe, which is inside the bin directory (for example, C:/path/to/qt-everywhere-opensource-build-4.8.6/bin/qmake.exe).
    • If building in debug mode: SimpleITK has to be disabled for building in debug mode. See more information at http://www.na-mic.org/Bug/view.php?id=3816 (you get this error if you attempt it: LINK : fatal error LNK1104: cannot open file 'python27_d.lib')
    • Click generate then close cmake-gui.
    • If building in release mode:
      • Open the top-level Slicer.sln file in the build directory in Visual Studio
      • Set active configuration to Release. Visual Studio will select Debug build configuration by default when you first open the solution in the Visual Studio GUI. If you build Slicer in release mode and accidentally forget to switch the build configuration to Release then the build will fail. Note: you can avoid this manual configuration mode selection by setting CMAKE_CONFIGURATION_TYPES to Release in cmake-gui.
    • If building in debug mode:
    • Build the ALL_BUILD project

Unix-like

  • Recommended: ccmake
    • Configure using the following commands. By default CMAKE_BUILD_TYPE is set to Debug.
mkdir Slicer-SuperBuild-Debug
cd Slicer-SuperBuild-Debug
cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DQT_QMAKE_EXECUTABLE:FILEPATH=/path/to/QtSDK/Desktop/Qt/486/gcc/bin/qmake ../Slicer

where you replace /path/to/QtSDK with the real path on your machine where QtSDK is located

  • Remarks:
  1. Using top-level directory name like Slicer-SuperBuild-Release or Slicer-SuperBuild-Debug is recommended.
  2. Step-by-step debug instuctions
  • On Mac OS X 10.9 (Mavericks) / 10.10 (Yosemite), also set the following variables (see discussion):
Variable Description
Slicer_USE_PYTHONQT_WITH_TCL OFF
CMAKE_OSX_DEPLOYMENT_TARGET 10.9 or 10.10

General information

Two projects are generated by either cmake, ccmake or cmake-gui.

One of them is in the top-level bin directory Slicer-SuperBuild and the other one is in the subdirectory Slicer-build:

Slicer-SuperBuild/Slicer-build
  1. The first project in Slicer-SuperBuild manages all the external dependencies of Slicer (VTK, ITK, Python, ...). To build Slicer for the first time, run make (or build the solution file in Visual Studio) in Slicer-SuperBuild, which will update and build the external libraries and if successful will then build the subproject Slicer-build.
  2. The second project in Slicer-SuperBuild/Slicer-build is the "traditional" build directory of Slicer. After local changes in Slicer (or after an svn update on the source directory of Slicer), only running make (or building the solution file in Visual Studio) in Slicer-SuperBuild/Slicer-build is necessary (the external libraries are considered built and up to date).
  3. Warning: An significant amount of disk space is required to compile Slicer in Debug (>10GB on Windows)

Workaround firewall blocking git protocol

  • Some firewall will be blocking the git protocol, a possible workaround is to configure Slicer disabling the option Slicer_USE_GIT_PROTOCOL. Then http protocol will be used instead. Consider also reading https://github.com/commontk/CTK/issues/33

Notes for advanced users

  • By default, if CMake finds Java on your machine, it automatically builds Java CLIs. If you don't want any Java in your Slicer (or if you don't want to install Java on your Mac Os X), you can pass -DCMAKE_DISABLE_FIND_PACKAGE_Java:BOOL=TRUE when configuring Slicer.
  • Same applies for OpenSSL: CMAKE_DISABLE_FIND_PACKAGE_OpenSSL:BOOL=TRUE can be passed when building Slicer for packaging.






BUILD Slicer

After configuration, start the build process in the Slicer-SuperBuild directory

Linux or MacOSX (Makefile) Windows (Visual Studio)

Start a terminal.

$ cd ~/Projects/Slicer-SuperBuild

$ make -j<NUMBEROFCORES>

In case of file download hash mismatch error, you need to acquire the latest wget, and build cmake with OpenSSL turned on. For more information, see here and here

Start Windows Explorer. Need help?

  1. Open Slicer-SuperBuild\Slicer.sln in Visual Studio
  2. Select build configuration. Usually Release or Debug
  3. Select menu Project -> Build Solution

If you make local changes to Slicer, open the solution file located in the directory Slicer-SuperBuild/Slicer-build instead. You should then be able to either build all projects or just a specific one.





RUN Slicer

Linux or MacOSX Windows

Start a terminal.

$ Slicer-SuperBuild/Slicer-build/Slicer

Start Windows Explorer. Need help?

Run Slicer-SuperBuild/Slicer-build/Slicer.exe

Notes:

  • Linux Ubuntu: if you have odd rendering artifacts, try disabling visual effects (System/Appearance/Visual Effects)
  • Windows: If build was OK, but it Slicer doesn't start (gives the error: [bin/Release/SlicerQT-real.exe] exit abnormally - Report the problem.) then one possible root cause is that you have a copy of Python26.dll in your windows system directory (e.g., c:\Windows\System32\python26.dll). The solution is to rename or remove the python dll in the system directory. See more details here: http://www.na-mic.org/Bug/view.php?id=1180






PACKAGE Slicer

Linux or MacOSX (Makefile) Windows (Visual Studio)

Start a terminal.

$ cd ~/Projects/Slicer-SuperBuild
$ cd Slicer-build

$ make package

Note: Make sure to patch VS2008 using the script fix-vc9-redist-manifests.ps1
Start Windows Explorer. Need help?

  1. Open Slicer-SuperBuild\Slicer-build\Slicer.sln in Visual Studio
  2. Select Release build configuration.
  3. In the Solution Explorer, right click on PACKAGE project and then select Build

Note: PACKAGE project can be found in the CMakePredefinedTargets folder. See here for more details.


Common errors

CMake complains during configuration

CMake may not directly show what's wrong; try to look for log files of the form BUILD/CMakeFiles/*.log (where BUILD is your build directory) to glean further information.

A tool returned an error code from "Generating vtksysProcessFwd9xEnc.c"

The application has failed to start because its side-by-side configuration is incorrect.
Please see the application event log or use the command-line sxstrace.exe tool for more detail.
Project : error PRJ0019: A tool returned an error code from "Generating
vtksysProcessFwd9xEnc.c"

Suggested solution: Install SP1 of Visual Studio

See also:

error: ‘class QList<QString>’ has no member named ‘reserve’

/nfs/Users/blowekamp/QtSDK/Desktop/Qt/474/gcc/include/QtCore/qdatastream.h: In function ‘QDataStream& operator>>(QDataStream&, QList<T>&) [with T = QString]’:
/nfs/Users/blowekamp/QtSDK/Desktop/Qt/474/gcc/include/QtCore/qstringlist.h:247:   instantiated from here
/nfs/Users/blowekamp/QtSDK/Desktop/Qt/474/gcc/include/QtCore/qdatastream.h:246: error: ‘class QList<QString>’ has no member named ‘reserve’

You have multiple Qt versions installed on your machine. Try removing the Qt version installed on the system.

libarchive.so: undefined reference to `SHA256_Update'

Linking CXX executable ../../../../../bin/MRMLLogicCxxTests
/home/benjaminlong/work/slicer/Slicer-SuperBuild-Debug/LibArchive-install/lib/libarchive.so: undefined reference to `SHA256_Update'
/home/benjaminlong/work/slicer/Slicer-SuperBuild-Debug/LibArchive-install/lib/libarchive.so: undefined reference to `SHA256_Final'
/home/benjaminlong/work/slicer/Slicer-SuperBuild-Debug/LibArchive-install/lib/libarchive.so: undefined reference to `SHA256_Init'
/home/benjaminlong/work/slicer/Slicer-SuperBuild-Debug/LibArchive-install/lib/libarchive.so: undefined reference to `MD5_Init'

Solution:

cd Slicer-SuperBuild
rm -rf LibArchive-*
make -j4

Details:

No rule to make target `/usr/lib/x86_64-linux-gnu/libGL.so'

See http://techtidings.blogspot.com/2012/01/problem-with-libglso-on-64-bit-ubuntu.html

X11 Window errors at start time

X Error: BadWindow (invalid Window parameter) 3
  Extension:    137 (Uknown extension)
  Minor opcode: 4 (Unknown request)
  Resource id:  0x4200199
X Error: BadWindow (invalid Window parameter) 3
  Extension:    137 (Uknown extension)
  Minor opcode: 4 (Unknown request)
  Resource id:  0x42001a6
X Error: BadWindow (invalid Window parameter) 3
  Extension:    137 (Uknown extension)
  Minor opcode: 4 (Unknown request)
  Resource id:  0x42001b3

Solution:

  • Reinstall Nvidia drivers (that also rewrite the xorg.conf file).

error C2061: syntax error : identifier 'ssize_t'

4>1>Compiling...
4>1>version.c
4>1>c:\chene\winbin64\slicer4\cmcurl\urldata.h(585) : error C2061: syntax error : identifier 'ssize_t'
4>1>c:\chene\winbin64\slicer4\cmcurl\urldata.h(593) : error C2365: 'fread' : redefinition; previous definition was 'function'
4>1>        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\stdio.h(248) : see declaration of 'fread'
4>1>c:\chene\winbin64\slicer4\cmcurl\urldata.h(610) : error C2059: syntax error : '}'

Solution:

ld: framework not found QtWebKit

[...]
Linking CXX shared library libPythonQt.dylib
ld: framework not found QtWebKit
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[8]: *** [libPythonQt.dylib] Error 1
[...]

See Slicer issue #2860

Workaround:

Solution:

On MacOSX 10.8, CMake hangs forever

Issue: http://www.na-mic.org/Bug/view.php?id=2957

Solution: Use CMake build >= 2.8.10.20130220-g53b279. See http://www.cmake.org/files/dev/cmake-2.8.10.20130220-g53b279-Darwin-universal.tar.gz

Details:

CMake folks (Thanks Brad King :)) fixed an issue that was preventing the most recent nightly from being used to successfully compile Slicer. The fix has been tested and is known to work. Tomorrow nightly build of CMake and by extension the coming release of CMake 2.8.11 will work.

If you are curious about the details, check the commit message:

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=1df09e57 [^]

The associated CMake test have also been updated:

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=bff3d9ce [^]



On MacOSX 10.8/10.9 with XQuartz, 'X11/Xlib.h' file not found

Issue: http://www.na-mic.org/Bug/view.php?id=3405

Workaround: Build with -DSlicer_USE_PYTHONQT_WITH_TCL:BOOL=OFF

Tcl is required only for EMSegment module.

Details: See http://www.na-mic.org/Bug/view.php?id=3405

svn: E175002: Unable to connect to a repository at URL XXX

Issue: Cisco AnyConnect is installed with the "Web Security" option checked (default), which blocks Subversion checkouts even when inactive!

Solution: Uninstall and reinstall Cisco AnyConnect, deselecting the "Web Security" feature during install

CiscoAnyConnectInstallOptions.png

My antivirus software reports that files in my build directory are infected

Although usually antivirus software does not interfere with the build process, it is recommended to disable antivirus and search indexing for build directories to improve performance and minimize the chance of concurrent file access problems.

Visual Studio compiler crashes

  • If you use Visual Studio 2008, make sure Visual Studio 2008 service pack 1 is installed
  • Build Slicer in a short directory, for example source code in C:\S4, binary directory C:\S4D or C:\S4R

'QSslSocket' : is not a class or namespace name

This error message occurs if Slicer is configured to use SSL but Qt is built without SSL support.

Either set Slicer_USE_PYTHONQT_WITH_OPENSSL to OFF when configuring Slicer build in CMake, or build Qt with SSL support.

Quick Build on Debian

sudo aptitude update
sudo aptitude install subversion git gcc g++ make cmake-curses-gui libqt4-dev
svn co http://svn.slicer.org/Slicer4/trunk Slicer
mkdir Slicer-SuperBuild-Debug
cd Slicer-SuperBuild-Debug
cmake ../Slicer
make -j5

# runtime dependency:
sudo aptitude install python-tk


Quick Build on Fedora 20

Thanks to Bill Lorensen, you will find below the instruction to quickly build Slicer on Fedora 20:

yum groupinstall "C Development Tools"
yum install git-core
yum install svn
yum install libX11-devel
yum install libXt-devel
yum install mesa-libGL-devel
yum install mesa-libGLU-devel
yum install cmake
yum install tcl-devel
yum install python-devel
yum install qt-devel
yum install qt-webkit-devel
svn co http://svn.slicer.org/Slicer4/trunk Slicer
mkdir Slicer-SuperBuild-Debug
cd Slicer-SuperBuild-Debug
cmake ../Slicer
make -j5

Reference: http://slicer-devel.65872.n3.nabble.com/Fedora-20-Slicer-Experience-tt4030845.html