0

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

m7913d
  • 10,244
  • 7
  • 28
  • 56
BeMeCollective
  • 618
  • 7
  • 15

1 Answers1

3

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} )
blowekamp
  • 1,401
  • 7
  • 7
  • blowekamp:Thanks for your response. How about a case where my existing program has already been written, and I am adding SimpleITK to it. Will I add libs manually to the project settings? – BeMeCollective Sep 19 '14 at 15:22
  • I've the same question. Could you comment blowekamp? – BmyGuest Oct 08 '14 at 22:51
  • Yes you will need to add all the libraries of ITK and SimpleITK manually. I still recommend trying to use CMake for your project. You can use the example cmake build and copy the libraries and include paths from that project into your own. – blowekamp Oct 15 '14 at 15:14