Two versions of VTK

I installed two versions of VTK in my ubuntu20.04

1, VTK9.1.0 in customed path /home/hitbuyi/PCL/VTK_9.1
in ~/.bashrc, I set the environment varibles like this

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/hitbuyi/PCL/VTK_9.1/lib/
export C_INCLUDE_PATH=$C_INCLUDE_PATH:/home/hitbuyi/PCL/VTK_9.1/include
export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/home/hitbuyi/PCL/VTK_9.1/include
export VTK_DIR=/home/hitbuyi/PCL/VTK_9.1
export PATH="/home/hitbuyi/PCL/VTK_9.1/bin:$PATH"

and the CMake can found VTK correctly, it’s oupt of is

-- VTK_VERSION: 9.1.0, Qt Version: 5.12.8
print_vtk_lib_module,VTK::CommonCoreVTK::CommonDataModelVTK::FiltersSourcesVTK::GUISupportQtVTK::InteractionStyleVTK::RenderingContextOpenGL2VTK::RenderingCoreVTK::RenderingFreeTypeVTK::RenderingGL2PSOpenGL2VTK::RenderingOpenGL2VTK::GUISupportQtVTK::RenderingQt

in CMakeLists.txt , use
find(VTK)
CMake can found VTK9.1 correctly, I print print_vtk_lib_module

1, VTK7.1.0 installed in default manner, its lib path, include path are in different folder, like this

camke

...
 /usr/lib/cmake/vtk-7.1
/usr/lib/cmake/vtk-7.1/VTKConfig.cmake
/usr/lib/cmake/vtk-7.1/VTKConfigVersion.cmake
/usr/lib/cmake/vtk-7.1/VTKGenerateExportHeader.cmake
 /usr/lib/cmake/vtk-7.1/vtkTestingMacros.cmake
/usr/lib/cmake/vtk-7.1/vtkTestingRenderingDriver.cmake
/usr/lib/cmake/vtk-7.1/vtkThirdParty.cmake
/usr/lib/cmake/vtk-7.1/Modules/vtkChartsCore-Headers.cmake
/usr/lib/cmake/vtk-7.1/Modules/vtkCommonColor-Headers.cmake
...

include

...
/usr/include/vtk-7.1/vtkSLACParticleReader.h
/usr/include/vtk-7.1/vtkSLACReader.h
/usr/include/vtk-7.1/vtkSLCReader.h
/usr/include/vtk-7.1/vtkSMPContourGrid.h
/usr/include/vtk-7.1/vtkSMPThreadLocal.h
/usr/include/vtk-7.1/vtkSMPThreadLocalObject.h
...

libs

...
/usr/lib/x86_64-linux-gnu/libvtkmetaio-7.1.so.7.1p.1
/usr/lib/x86_64-linux-gnu/libvtkproj4-7.1.so
/usr/lib/x86_64-linux-gnu/libvtkproj4-7.1.so.7.1p
/usr/lib/x86_64-linux-gnu/libvtkxdmf2-7.1.so
/usr/lib/x86_64-linux-gnu/libvtkxdmf2-7.1.so.7.1p
/usr/lib/x86_64-linux-gnu/libvtkxdmf2-7.1.so.7.1p.1
....

in CMakeLists.txt file, I set like this

set(VTK_INCLUDE_DIRS "/usr/include/vtk-7.1")
#SET(VTK_DIR "/usr/lib/cmake/vtk-7.1/VTKConfig.cmake")
SET(VTK_DIR "/usr/lib/cmake/vtk-7.1/")
set(VTK_LIBRARIES, "/usr/lib/x86_64-linux-gnu")

target_link_libraries(MinimalQtVTKApp
${VTK_LIBRARIES}
#/usr/lib/x86_64-linux-gnu/
)

not use find(VTK)
During the compiling stage, CMake can’t no find VTK7.1.0 correctly, ${VTK_LIBRARIES} is null

in my case, How to set CMakeLists.txt to find VTK7.1.0 correctly?

The comma in your call to set looks wrong.

I remove the comma,


set(VTK_INCLUDE_DIRS "/usr/include/vtk-7.1")
#SET(VTK_DIR  "/usr/lib/cmake/vtk-7.1/VTKConfig.cmake")
SET(VTK_DIR  "/usr/lib/cmake/vtk-7.1/")
set(VTK_LIBRARIES  "/usr/lib/x86_64-linux-gnu")

target_link_libraries(MinimalQtVTKApp
${VTK_LIBRARIES}
#/usr/lib/x86_64-linux-gnu/
)

still VTK not found by CMake

/usr/bin/ld: CMakeFiles/VSCodeCMakeDemo.dir/VSCodeCMakeDemo_autogen/mocs_compilation.cpp.o: in function `__static_initialization_and_destruction_0(int, int)':
mocs_compilation.cpp:(.text+0x2a3): undefined reference to `vtkDebugLeaksManager::vtkDebugLeaksManager()'
/usr/bin/ld: mocs_compilation.cpp:(.text+0x2b8): undefined reference to `vtkDebugLeaksManager::~vtkDebugLeaksManager()'
/usr/bin/ld: mocs_compilation.cpp:(.text+0x37e): undefined reference to `vtkObjectFactoryRegistryCleanup::vtkObjectFactoryRegistryCleanup()'
/usr/bin/ld: mocs_compilation.cpp:(.text+0x393): undefined reference to `vtkObjectFactoryRegistryCleanup::~vtkObjectFactoryRegistryCleanup()'
/usr/bin/ld: CMakeFiles/VSCodeCMakeDemo.dir/VSCodeCMakeDemo_autogen/mocs_compilation.cpp.o: in function `vtkRenderingOpenGL_ModuleInit::vtkRenderingOpenGL_ModuleInit()':
mocs_compilation.cpp:(.text._ZN29vtkRenderingOpenGL_ModuleInitC2Ev[_ZN29vtkRenderingOpenGL_ModuleInitC5Ev]+0x11): undefined reference to `vtkRenderingOpenGL_AutoInit_Construct()'
/usr/bin/ld: CMakeFiles/VSCodeCMakeDemo.dir/VSCodeCMakeDemo_autogen/mocs_compilation.cpp.o: in function `vtkRenderingOpenGL_ModuleInit::~vtkRenderingOpenGL_ModuleInit()':
mocs_compilation.cpp:(.text._ZN29vtkRenderingOpenGL_ModuleInitD2Ev[_ZN29vtkRenderingOpenGL_ModuleInitD5Ev]+0x11): undefined reference to `vtkRenderingOpenGL_AutoInit_Destruct()'
/usr/bin/ld: CMakeFiles/VSCodeCMakeDemo.dir/VSCodeCMakeDemo_autogen/mocs_compilation.cpp.o: in function `vtkInteractionStyle_ModuleInit::vtkInteractionStyle_ModuleInit()':
mocs_compilation.cpp:(.text._ZN30vtkInteractionStyle_ModuleInitC2Ev[_ZN30vtkInteractionStyle_ModuleInitC5Ev]+0x11): undefined reference to `vtkInteractionStyle_AutoInit_Construct()'
/usr/bin/ld: CMakeFiles/VSCodeCMakeDemo.dir/VSCodeCMakeDemo_autogen/mocs_compilation.cpp.o: in function `vtkInteractionStyle_ModuleInit::~vtkInteractionStyle_ModuleInit()':
mocs_compilation.cpp:(.text._ZN30vtkInteractionStyle_ModuleInitD2Ev[_ZN30vtkInteractionStyle_ModuleInitD5Ev]+0x11): undefined reference to `vtkInteractionStyle_AutoInit_Destruct()'
/usr/bin/ld: CMakeFiles/VSCodeCMakeDemo.dir/main.cpp.o: in function `__static_initialization_and_destruction_0(int, int)':

You are setting VTK_LIBRARIES to a path, then giving that to target_link_libraries(). I’m not sure what you were expecting to happen with that arrangement, but it isn’t valid. target_link_libraries() expects the argument to be either a CMake target, an actual library name, a full path to a library file, or a linker option. It doesn’t appear to be any of those.

I realized that error, a path to target_link_libaries is invaid in fact. the following set is valid

SET(VTK_DIR  "/usr/lib/cmake/vtk-7.1/")
find_package(VTK 7.1 REQUIRED)
if(VTK_FOUND)
  include_directories(${VTK_INCLUDE_DIRS})
  message(status,"ytxVTKINC",${VTK_INCLUDE_DIRS})
endif()

then VTK7.1 is found already, the error during the linking stage is another issue on different versions of VTK libs

Thanks anyway