Problem in parsing ITK_LIBRARIES

I am trying to run a simple HelloWorld program, and make an inclusion of header file of ITK: itkImage.h.

Running cmake …/src to build the Makefile is okay. But running make all gives this error: /src/HelloWorldTwo.cpp:10:22: fatal error: itkImage.h: No such file or directory
#include “itkImage.h”

Find below my CMakeLists.txt file and HelloWorldTwo.cpp, and debugging variables. I knew that ITK_LIBRARIES should be semicolon separated, but they aren’t! I wonder what I should check? Or what I did wrong in first place?

CMakeLists.txt:
cmake_minimum_required(VERSION 3.6.2)
project(HelloWorldTwo)
set(ITK_DIR “/home/usr/itk/lib/cmake/ITK-4.13”)
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
add_executable(HelloWorldTwo HelloWorldTwo.cpp)
target_link_libraries(HelloWorldTwo ${ITK_LIBRARIES})
MESSAGE( STATUS "ITK_DIR: " ${ITK_DIR} )
MESSAGE( STATUS "ITK_LIBRARIES: " ${ITK_LIBRARIES} )
MESSAGE( STATUS "ITK_USE_FILE: " ${ITK_USE_FILE} )

HelloWorldTwo.cpp:
#include “iostream”
#include “itkImage.h”
using namespace std;
int main() {
cout << “Hello World!!!” << endl; // prints Hello World!!!
return 0;
}

Debugging the variables in CMakeLists.txt:
– ITK_DIR: /home/usr/itk/lib/cmake/ITK-4.13
– ITK_USE_FILE: /home/usr/itk/lib/cmake/ITK-4.13/UseITK.cmake
– ITK_LIBRARIES: itkdouble-conversionitksysitkvnl_algoitkvnlitkv3p_netlibitknetlibitkvclITKCommonitkNetlibSlatecITKStatisticsITKTransformITKLabelMapITKMeshitkzlibITKMetaIOITKSpatialObjectsITKPathITKQuadEdgeMeshITKIOImageBaseITKOptimizersITKPolynomialsITKBiasCorrectionITKBioCellITKDICOMParserITKEXPATITKIOXMLITKIOSpatialObjectsITKFEMgdcmDICTgdcmMSFFITKznzITKniftiioITKgiftiiohdf5_cpp-statichdf5-staticITKIOBMPITKIOBioRadITKIOBrukerITKIOCSVITKIOGDCMITKIOIPLITKIOGEITKIOGIPLITKIOHDF5itkjpegITKIOJPEGitktiffITKIOTIFFITKIOLSMitkminc2ITKIOMINCITKIOMRCITKIOMeshITKIOMetaITKIONIFTIITKNrrdIOITKIONRRDitkpngITKIOPNGITKIOSiemensITKIOStimulateITKTransformFactoryITKIOTransformBaseITKIOTransformHDF5ITKIOTransformInsightLegacyITKIOTransformMatlabITKIOVTKITKKLMRegionGrowingitklbfgsITKOptimizersv4itkopenjpegITKVTKITKWatershedsITKReviewITKVideoCoreITKVideoIOITKVtkGlue

1 Like

Not sure what’s wrong in your CMakeList.txt at first sight (I’d think of ITK_DIR or the way you built ITK), you may find it useful to visit the
BuildAHelloWorldProgram example
to get you started with a simple ITK program.

HTH.

But ITK_DIR contains the files needed to include ITK_LIBRARIES: (ITKconfig.cmake) and other files as well.
I have checked the example you mentioned, and it is typically what I am doing. I think my issue concerns ITK_LIBRARIES. Do you have them separated by semicolon?

No, that’s not likely the issue: they are not separated with commas in my case either.

Let us know what happen if you try:

target_link_libraries(HelloWorldTwo PUBLIC ${ITK_LIBRARIES})

Also, there is a lonely #include there, not sure if your .cpp file is like that or just a typo copying it here.

It gives same result. And secondly, it is just typo: it is #include “iostream”

I cannot reproduce it :confused:. It works for me using:

HelloWorldTwo.cpp

#include <iostream>
#include "itkImage.h"
using namespace std;
int main() {
cout << "Hello World!!!" << endl; // prints Hello World!!!
return 0;
}
cmake_minimum_required(VERSION 3.6.2)
project(HelloWorldTwo)
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
add_executable(HelloWorldTwo HelloWorldTwo.cpp)
target_link_libraries(HelloWorldTwo ${ITK_LIBRARIES})
MESSAGE( STATUS "ITK_DIR: " ${ITK_DIR} )
MESSAGE( STATUS "ITK_LIBRARIES: " ${ITK_LIBRARIES} )
MESSAGE( STATUS "ITK_USE_FILE: " ${ITK_USE_FILE} )

and running it with cmake -DITK_DIR:PATH=/path/cmake/ITK ../src

Maybe you can try to set ITK_DIR with cmake interface (or ccmake) instead of hard-coding it in CMakeLists.txt?
Umm, not sure what’s going on, maybe somebody else has a clue. I would recommend to try in a new build folder to start in a clean state.

1 Like