I am relatively new to CMake
, and I have developed a small project which builds a library that links to a shared library, named external_library
. My CMakeLists.txt
file looks something like this:
cmake_minimum_required(VERSION 2.8.12)
project(project_name)
include_directories(path_to_external_library_source_code)
add_subdirectory(path_to_external_library_header_files subproject/external_library)
target_link_libraries(project_name external_library)
install(TARGETS project_name DESTINATION installation_path)
When I build the project (using make
), it works perfectly, and it creates the links correctly (I have checked it with the ldd
command). However, when I try to install it (with make install
), the generated file in the installation path is not linked against the specified shared library.
Using ldd
again, I have checked that the shared library is not found by the library generated in the installation path, although it is found in the library generated in the build path. How could I fix this?
Thanks.
Pd: I am using CMake 3.5.1
in Ubuntu 16.04.2 LTS
.
I have found that the problem can be solved using the command find_library
, specifying the path of the built shared library, doing something like this:
cmake_minimum_required(VERSION 2.8.12)
project(project_name)
include_directories(path_to_external_library_source_code)
find_library(LIBNAME LibName_1 LibName_2 HINTS built_lib_directory)
target_link_libraries(project_name ${LIBNAME})
install(TARGETS project_name DESTINATION installation_path)