cmake-examples icon indicating copy to clipboard operation
cmake-examples copied to clipboard

`01-basic/E-installing`: cannot open shared object file

Open syheliel opened this issue 2 years ago • 1 comments

here is my command and output:

❯ cmake -B ./build/ -DCMAKE_EXPORT_COMPILE_COMMANDS=on && sudo cmake --build build --target install
-- The C compiler identification is GNU 11.2.0
-- The CXX compiler identification is GNU 11.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/xxx/git/cmake-examples/01-basic/E-installing/build
[ 25%] Building CXX object CMakeFiles/cmake_examples_inst.dir/src/Hello.cpp.o
[ 50%] Linking CXX shared library libcmake_examples_inst.so
[ 50%] Built target cmake_examples_inst
[ 75%] Building CXX object CMakeFiles/cmake_examples_inst_bin.dir/src/main.cpp.o
[100%] Linking CXX executable cmake_examples_inst_bin
[100%] Built target cmake_examples_inst_bin
Install the project...
-- Install configuration: ""
-- Installing: /usr/local/bin/cmake_examples_inst_bin
-- Set runtime path of "/usr/local/bin/cmake_examples_inst_bin" to ""
-- Installing: /usr/local/lib/libcmake_examples_inst.so
-- Up-to-date: /usr/local/include
-- Up-to-date: /usr/local/include/installing
-- Up-to-date: /usr/local/include/installing/Hello.h
-- Up-to-date: /usr/local/etc/cmake-examples.conf

reopen the terminal and then run cmake_examples_inst_bin gives following error:

cmake_examples_inst_bin: error while loading shared libraries: libcmake_examples_inst.so: cannot open shared object file: No such file or directory

output of ldd:

ldd $(which cmake_examples_inst_bin)
	linux-vdso.so.1 (0x00007ffe6751d000)
	libcmake_examples_inst.so => not found
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f1713bc0000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f1713e00000)

syheliel avatar Jul 05 '22 02:07 syheliel

set_target_properties(cmake_examples_inst_bin PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib )

You can add the command above before running the 'install(cmake_examples_inst_bin)' to tell the system to look for shared libraries in "${CMAKE_INSTALL_PREFIX}/lib" when running the cmake_examples_inst_bin executable

KaivinC avatar Jun 04 '23 07:06 KaivinC