Undefined Reference error in using simpleitk in C++

I installed the simpleitk in my ubuntu 16.04 as described in this link (Building simpleITK) and I’m trying to use with QT creator. The problem is that I’m getting lots of undefined reference error, but I included ALL the .a files contained in the SimpleITK-build/lib and ITK-build/lib folder.

When I try to use the python code, the SimpleItk works fine. So, what am I missing?
Thanks.

Please using CMake with Qt Creator: https://doc.qt.io/qtcreator/creator-project-cmake.html

With CMake to use SimpleITK you simply need to add:

find_package(SimpleITK REQUIRED)
...
target_link_libraries ( YourExecutable ${SimpleITK_LIBRARIES} )

SimpleITK uses modern CMake with target attributes so the required compiler flags and include paths are automatically added. It is possible to create a minimal CMake project, configure it, then copy the build parameters to Qt Creator. However, this is a fragile and unsupported workflow.

You question here is missing the same information necessary for an informed answer what was originally missing from stack overflow.

2 Likes

Thanks, Bradley.

So, for compiling I have to use the cmake instead of qmake? I’m asking this because I’m not very familiar with cmake, but if necessary I can learn more.

It is recommended and supported to use CMake. with SimpleITK C++ interface. Time can be spent hacking at unsupported usage, or learning another useful tool.

1 Like

Blowekamp, I created a cmakelist file with your recommendation but the cmake returns me some error message:

CMake Error at /home/felippe/SimpleITK-build/lib/cmake/SimpleITK-1.3/SimpleITKConfig.cmake:67 (find_package):
By not providing “FindITK.cmake” in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by “ITK”, but
CMake did not find one.

Could not find a package configuration file provided by “ITK” (requested
version 4.13.2) with any of the following names:

ITKConfig.cmake
itk-config.cmake

Add the installation prefix of “ITK” to CMAKE_PREFIX_PATH or set “ITK_DIR”
to a directory containing one of the above files. If “ITK” provides a
separate development package or SDK, be sure it has been installed.
Call Stack (most recent call first):
CMakeLists.txt:4 (find_package)

Configuring incomplete, errors occurred!
See also “/home/felippe/Área de Trabalho/Felippe/Mestrado/C_plus_plus/Codigos/build-Registration_ITK_CMAKE-Desktop_Qt_5_12_3_GCC_64bit-Default/CMakeFiles/CMakeOutput.log”.
CMake Deprecation Warning:
The ‘cmake-server(7)’ is deprecated. Please port clients to use the
‘cmake-file-api(7)’ instead.

CMake Project parsing failed.

So, I did what it was recommended, I set the both (but not in the same time) variables ITK_DIR and CMAKE_PREFIX_PATH, as you can see below:

cmake_minimum_required(VERSION 3.10)

project(Registration_ITK_CMAKE)
find_package(SimpleITK REQUIRED)
#set(ITK_DIR "/home/felippe/SimpleITK-build/ITK-prefix/lib/cmake/ITK/")
set(CMAKE_PREFIX_PATH "/home/felippe/SimpleITK-build/ITK-prefix/")
add_executable(${PROJECT_NAME} "main.cpp")
target_link_libraries ( YourExecutable ${SimpleITK_LIBRARIES} )

So, what am I missing again?

Thanks.

Hello,

Looks like you are making good progress. I usually set ITK_DIR what should have looks right to me. What is the content of /home/felippe/SimpleITK-build/ITK-prefix/lib/cmake/ITK/? I have the following:

 $ls SimpleITK/ITK-prefix/lib/cmake/ITK/
ITKConfig.cmake					ITKTargets-release.cmake			UseITK.cmake
ITKConfigVersion.cmake				ITKTargets.cmake				itkImageIOFactoryRegisterManager.h.in
ITKModuleAPI.cmake				Modules						itkTransformIOFactoryRegisterManager.h.in
1 Like

I have this:

felippe@felippe-pc:~/SimpleITK-build/ITK-prefix/lib/cmake/ITK$ ls
ITKConfig.cmake
ITKConfigVersion.cmake
itkImageIOFactoryRegisterManager.h.in
ITKModuleAPI.cmake
ITKTargets.cmake
ITKTargets-release.cmake
itkTransformIOFactoryRegisterManager.h.in
Modules
UseITK.cmake

It seems the same…

I’m compiling using cmake together with QT (qt has an option of compiling using cmake instead of the qmake).

You need to set ITK_DIR before calling find_package(SimpleITK REQUIRED).

I usual set ITK_DIR and SimpleITK_DIR on the command line during configuration like this:

-DSimpleITK_DIR=/scratch/blowekamp/SimpleITK/lib/cmake/SimpleITK-1.3/ -DITK_DIR=/scratch/blowekamp//SimpleITK/ITK-prefix/lib/cmake/ITK/ .
1 Like

Problem Solved. Thank you very much blowekamp, you saved me!!!

1 Like