Required to call `ldconfig` after installing from source
I ran the following commands on Ubuntu 18.04:
$ wget https://gitlab.kitware.com/vtk/vtk/-/archive/v8.2.0/vtk-v8.2.0.tar.gz
$ tar xf vtk-v8.2.0.tar.gz
$ cmake -Hvtk-v8.2.0 -Bvtk-v8.2.0/build \
-DBUILD_SHARED_LIBS=ON \
-DBUILD_TESTING=OFF \
-DCMAKE_BUILD_TYPE=Release \
-DVTK_Group_StandAlone=OFF \
-DModule_vtkIOGeometry=ON \
-DModule_vtkFiltersFlowPaths=ON \
-DVTK_USE_X=OFF \
-DVTK_OPENGL_HAS_OSMESA=ON
$ sudo make -C vtk-v8.2.0/build install
Note: Because I am not providing
CMAKE_INSTALL_PREFIX
, VTK will automatically be installed in/usr/local/lib
.
Then, in my project, I added the following CMakeLists.txt
:
cmake_minimum_required(VERSION 2.8.7)
project(example)
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
IF("${isSystemDir}" STREQUAL "-1")
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
ENDIF("${isSystemDir}" STREQUAL "-1")
find_package(VTK 8 REQUIRED NO_MODULE)
include(${VTK_USE_FILE})
add_executable(example main.cpp)
target_link_libraries(example ${VTK_LIBRARIES})
Every time I tried to run the executable, it would output the following error message:
example: error while loading shared libraries: libvtksys-8.2.so.1: cannot open shared object file: No such file or directory
I was stuck for a pretty long time and finally figured out that running ldconfig
fixes the problem. I was wondering if anyone else has run into the same problem? Is running ldconfig
after installing VTK a common thing to do? I never had to do this before and I have manually built and installed quite a lot of libraries. I don't know if this is the right place to ask my question. Sorry if it is not!