VTK error : linking shared libraries?

I just built and installed VTK version 9.0.1 for my ubuntu . I downloaded the cylinder example from the official site and was able to build it fine after fixing the RenderingContextOpenGL2 variable. But when i run the executable file , it displays this error:
./CylinderExample: error while loading shared libraries: libvtkFiltersExtraction-9.0.so.1: cannot open shared object file: No such file or directory
even though VTK is successfully installed and I was able to locate that shared object file in usr/local/lib

1 Like

Did you run ldconfig after installation?

When you install .deb packages, ldconfig runs automatically. But when you install manually with make install, you usually have to run ldconfig yourself.

If running ldconfig doesn’t help, then check /etc/ld.so.conf.d/libc.conf (or /etc/ld.so.conf) to make sure that /usr/local/lib is in your library path.

2 Likes

It worked! I ran the ldconfig command from the build directory and now the example works. I’m new to Linux and this is my second make installation after opencv but had used opencv directly in my programs and not makefiles. Thanks for the help!
I needed vtk because I read that cv::viz is built on it and couldn’t find the header in my include files. Do I need to rebuild and install opencv with vtk enabled for this ? Or is there any simpler fix?

If you installed opencv via apt, apt-get, or the synaptics package manager then you should be able to do the same with cv::viz, and then the VTK package will be brought in automatically as a dependency.

apt-get install libopencv-viz-dev

But if you installed opencv from source code, then yes, you will have to re-configure opencv to build against VTK, and then rebuild and re-install opencv.

Thanks again for the response! I installed it from source code and was trying to rebuild it. i get this error now:

CMake Error at /usr/local/lib/cmake/vtk-9.0/vtkModule.cmake:2955 (get_property):
get_property could not find TARGET opencv_viz. Perhaps it has not yet been
created.
Call Stack (most recent call first):
/home/astropiu/Downloads/opencv_contrib-master/modules/viz/CMakeLists.txt:43 (vtk_module_autoinit)
modules/world/CMakeLists.txt:13 (include)
modules/world/CMakeLists.txt:32 (include_one_module)

CMake Error at /usr/local/lib/cmake/vtk-9.0/vtkModule.cmake:2962 (target_compile_definitions):
Cannot specify compile definitions for target “opencv_viz” which is not
built by this project.
Call Stack (most recent call first):
/home/astropiu/Downloads/opencv_contrib-master/modules/viz/CMakeLists.txt:43 (vtk_module_autoinit)
modules/world/CMakeLists.txt:13 (include)
modules/world/CMakeLists.txt:32 (include_one_module)

This same error was posted by someone at opencv forum but is still unanswered. Should i try using previous version of vtk or opencv?

I don’t know which versions of opencv work with which versions of VTK. @opoplawski, do you have any experience with this?

I was able to build opencv 4.3.0 against vtk 9 with the addition of these upstream patches:

Patch1: https://patch-diff.githubusercontent.com/raw/opencv/opencv/pull/17431.patch
Patch2: https://patch-diff.githubusercontent.com/raw/opencv/opencv_contrib/pull/2549.patch

Looks like they made it into the 4.4.0 release.

I was able to build opencv 4.4.0 with vtk 8.2 without any issues through the same procedure that I tried with 9.0.1. I guess the latest releases aren’t compatible.