0
votes

I'm learning CMake.

My project consists of an executable and a shared library. The shared library can be used by third party projects. The executable and the shared library will be installed in the system.

I have two modes of development: debug and release. Simply, I define an option and, depending on the value of the option, set a value to the CMAKE_BUILD_TYPE variable.

I link the executable with the shared library as follows:

ADD_EXECUTABLE( my_executable ${MY_EXECUTABLE_SOURCE_FILES} )
TARGET_LINK_LIBRARIES(
  my_executable
  ${MY_EXECUTABLE_DEPENDENCIES_LIBRARIES}
  my_shared_library #target generated with ADD_LIBRARY
)

My problem is that when I link in release mode and I run the ldd tool:

~/my-project/build$ sudo make install
~/my-project/build$ ldd -d /usr/local/bin/my_executable

my_shared_library.so.0.1 => /path/my-project/output/lib/my_shared_library.so.0.1 (0x00007f1361adb000)
                            ------------------------
                                   local path

when it should be displayed:

my_shared_library.so.0.1 => /usr/local/lib/my_shared_library.so.0.1 (0x00007f1361adb000)
                            -----------
                            install path

How can I solve this problem?

Should I create a static library (a part of the shared library) and link the executable with it?

Cheers

1
Have you run ldd on the executable in the system path from somewhere else than the build path?Torbjörn
Side note: You should not be required to code an additional option for the switch between Debug and Release mode. Let the user either specify CMAKE_BUILD_TYPE directly on the first invocation of CMake or during building: cmake --build . --target my_executable --config Debug|SharedTorbjörn
@torbjörn I want to use CPack to generate a debian package. When I install the package on another system and run the executable, fails because it can not find the shared library. I have to modify the LD_LIBRARY_PATH variable to run the executable.Juan Solo
And the library gets installed too when you run sudo make install? Try to create a mcve.Torbjörn
Yes, the library is installed. The problem is that the executable searches the library in an incorrect path. For this reason, I have to modify the LD_LIBRARY_PATH variable.Juan Solo

1 Answers

0
votes

The solution that I've found: Object Libraries

Cheers