您好我在使用cmake 2.8.12
在ubuntu上链接两个库时遇到问题目录结构
libraries
\lib1
CMakeLists.txt
source1.cpp
\lib2
CMakeLists.txt
source2.cpp
build
lib1的CMakeLists.txt
cmake_minimum_required(VERSION 2.8.4)
project(lib1)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ../../build/)
set(BASE_DIR ../)
set(SOURCE_FILES source1.cpp)
include_directories ("${BASE_DIR}")
add_library(lib1 SHARED ${SOURCE_FILES})
target_include_directories (lib1 PUBLIC ${BASE_DIR})
这构建良好。
然后对于lib2我有以下CMakeLists.txt
cmake_minimum_required(VERSION 2.8.4)
project(lib2)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ../../build)
set(BASE_DIR ../)
set(SOURCE_FILES
source2.cpp)
include_directories ("${BASE_DIR}")
add_library(lib2 SHARED ${SOURCE_FILES})
# include lib1
list(APPEND CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
find_library(lib1 lib1)
target_link_libraries(lib2 LINK_PUBLIC lib1)
我来了
链接CXX共享库../ build / liblib2.so
/ usr / bin / ld:找不到-llib1
我不清楚如何使用CMake正确链接这两个共享库。任何人都知道出了什么问题。
干杯,迈克
答案 0 :(得分:4)
1)如果你使用
target_include_directories (lib1 PUBLIC ${BASE_DIR})
为什么你认为你需要
include_directories ("${BASE_DIR}")
2)试试这个:
find_library(lib1_location lib1)
message("Lib1 is at: ${lib1_location}")
target_link_libraries(lib2 LINK_PUBLIC ${lib1_location})
看看会发生什么。
3)见http://www.cmake.org/cmake/help/v3.0/manual/cmake-packages.7.html