cmake_minimum_required(VERSION 3.17)
project(ConvertAnitkImageTovtkImageData)
set(CMAKE_CXX_STANDARD 11)
# and I add the next two lines , otherwise it told me can't find .h files
include_directories("/usr/local/include/ITK-5.1")
include_directories("/usr/local/include/vtk-9.0")
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
add_executable(ConvertAnitkImageTovtkImageData Code.cxx)
target_link_libraries(ConvertAnitkImageTovtkImageData ${ITK_LIBRARIES})
It’s Ok when I ran cmake. But an error occurred just like the title.
Also I wanna ask , I have tried the helloWorld project like this https://itk.org/ITKExamples/src/Core/Common/BuildAHelloWorldProgram/Documentation.html
it works good with the “raw” CMakeLists.txt (without include_directories(XXX) )
but when I try to compile it without cmake , just like this
" g++ helloWorld.cxx -o helloWorld -std=c++11 "
an error occurred that “itkImage.h not found”
and I tried again " g++ helloWorld.cxx -o HelloWorld -std=c++11 -I /usr/local/include/ITK-5.1 "
there is the same error as the images show
Yeah I have tried it. And it makes no difference
I’m now thinking about whether it’s because cmake has found a wrong path(for I have ever installed vmtk which uses VTK-8.1 and I compiled VTK-9.0)
Did you know how to assign a fixed path?
I have tried to use like these
set(VTK_DIR , “XXX”)
set(CMAKE_INCLUDE_PATH “XXX”)
find_package(ITK PATH_SUFFIXES “XXX”)
but it seems that cmake always first find VTK from vmtk , only if I do this
find_package(VTK 9.0 XXXX)
can cmake find the right one
Well…After I typed the words above I tried again with adding find/link VTK and set it’s VERSION , and it worked. Thanks a lot for your help !
You should do find ITK first, because it should get the correct version of VTK it was built against. Then do find VTK - it should get the same version from ITK. I think this is the correct order. The order was important some years ago, and might still be.
Yeah it will be good if I can help somebody else , while I’m not good at using cmake so this may not be a good example , but anyway , here is my “CMakeLists.txt”