# Two versions of VTK

**URL:** <https://discourse.cmake.org/t/two-versions-of-vtk/10772>\
**Category:** Code\
**Created:** [May 1, 2024, 1:54pm UTC](https://discourse.cmake.org/t/two-versions-of-vtk/10772 "2024-05-01T13:54:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hitbuyi](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hitbuyi/32/4543_2.png) [@hitbuyi](https://discourse.cmake.org/u/hitbuyi)\
**Post date:** [May 1, 2024, 1:54pm UTC](https://discourse.cmake.org/t/two-versions-of-vtk/10772/1 "2024-05-01T13:54:56Z")

</div>

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

```auto
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

```auto
-- 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

```auto
...
 /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

```auto
...
/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

```auto
...
/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

```auto
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?

---

<div class="post-metadata">

**Author:** ![alex](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alex/32/125_2.png) [@alex](https://discourse.cmake.org/u/alex)\
**Post date:** [May 3, 2024, 2:21am UTC](https://discourse.cmake.org/t/two-versions-of-vtk/10772/2 "2024-05-03T02:21:30Z")

</div>

The comma in your call to set looks wrong.

---

<div class="post-metadata">

**Author:** ![hitbuyi](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hitbuyi/32/4543_2.png) [@hitbuyi](https://discourse.cmake.org/u/hitbuyi)\
**Post date:** [May 3, 2024, 6:01am UTC](https://discourse.cmake.org/t/two-versions-of-vtk/10772/3 "2024-05-03T06:01:37Z")

</div>

> [@hitbuyi](#):
>
> ```auto
> 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/
> )
> 
> ```

I remove the comma,

```auto

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

```auto
/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)':

```

---

<div class="post-metadata">

**Author:** ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)\
**Post date:** [May 3, 2024, 10:46pm UTC](https://discourse.cmake.org/t/two-versions-of-vtk/10772/4 "2024-05-03T22:46:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![hitbuyi](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hitbuyi/32/4543_2.png) [@hitbuyi](https://discourse.cmake.org/u/hitbuyi)\
**Post date:** [May 4, 2024, 9:11am UTC](https://discourse.cmake.org/t/two-versions-of-vtk/10772/5 "2024-05-04T09:11:51Z")

</div>

I realized that error, a path to target\_link\_libaries is invaid in fact. the following set is valid

```auto
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
