我对CMake
相对较新,我开发了一个小型项目,它构建了一个链接到共享库的库,名为external_library
。我CMakeLists.txt
文件看起来是这样的:cmake:“make install”不会链接到Ubuntu中的库
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)
当我建项目(使用make
),它完美的作品,并正确创建的链接(我与ldd
命令检查的话)。但是,当我尝试安装它时(使用make install
),安装路径中生成的文件未链接到指定的共享库。
再次使用ldd
我已检查共享库未在安装路径中生成的库中找到,尽管它在构建路径中生成的库中找到。我怎么能解决这个问题?
谢谢。
Pd:我在Ubuntu 16.04.2 LTS
中使用CMake 3.5.1
。
你觉得'add_subdirectory(path_to_external_library_header_files subproject/external_library)'做了什么? 'path_to_external_library_header_files'中是否有CMakeLists.txt文件?你为什么试图把外部图书馆作为一部分的工作项目? – kdopen
是的,在'path_to_external_library_header_files'中有'CMakeLists.txt',它将共享库的'.cpp'和'.h'文件添加到项目中。 – GLR
我想让共享库成为创建的库的一部分,这就是为什么我使用'add_subdirectory'(我希望我做的是正确的)。 – GLR