background:
There is a C++ project, and the dynamic library libc++.so is generated after compilation.
Create a new c project, encapsulate the previous c++ project interface, and generate a dynamic library libc.so after compilation.
phenomenon:
After make install, the libc.so and libc++.so generated in the build will be copied to the lib directory at the same level as the build.
Executing ldd libc.so in the lib folder will not find libc++.so,
But you can find it by executing ldd libc.so in the build folder.
solve:
This is related to rpath, which is the path for so to find dependent libraries.
You can view RPATH through readelf -d libc.so
Then you can set RPATH in cmakelists.txt
set_target_properties(${PROJECT_NAME} PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")