Search code examples
c++cmakeimagingitksimpleitk

SimpleITK linking from Visual Studio 2008


This is a question for anyone using SimpleITK from within a C++ program.

I have downloaded the SimpleITK code, and generated the VS2008 .sln files using CMake as per SimpleITK instructions (Superbuild).

In the SimpleITK-build\lib\Debug I get a few SimpleITK libs eg: SimpleITKCommon-0.8.lib. In SimpleITK-build\ITK-build\lib\Debug I get many ITK libs eg: ITKCommon-4.5.lib

In the code, I use: #include "SimpleITK.h"

Question: What do I link to?

I can add to linker/input/additional dependencies all the SimpleITK libs one by one. Then I get unresolved external symbols, as I have not linked to the ITK libs (there are like 50 of them). I can't believe I need to add to additional dependencies 50-60 libs.

What am I missing here? can't find any documentation about linking into SimpleITK fom C++.

Thanks and cheers

Ari


Solution

  • It is recommend to use CMake. You are correct that you would need to add all those libraries if you were to do it manually.

    From the SimpleITK/Examples/CMakeLists.txt file here is how to create a project using CMake:

    find_package(SimpleITK REQUIRED)
    include(${SimpleITK_USE_FILE})
    
    # Add compiler flags needed to use SimpleITK.
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SimpleITK_REQUIRED_C_FLAGS}")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SimpleITK_REQUIRED_CXX_FLAGS}")
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SimpleITK_REQUIRED_LINK_FLAGS}")
    set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${SimpleITK_REQUIRED_LINK_FLAGS}")
    set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${SimpleITK_REQUIRED_LINK_FLAGS}")
    
    add_executable ( SimpleGaussian SimpleGaussian.cxx )
    target_link_libraries ( SimpleGaussian ${SimpleITK_LIBRARIES} )