link cmake 在 c 中的外部 *.so 库
link external *.so library in c by cmake
我正在尝试在我的 C 项目中使用 libtidy。
我构建整洁的代码并获得 *.so 文件。
当我尝试通过 cmake 将此文件 link 添加到我的项目时,收到以下错误消息:
CMake Error at CMakeLists.txt:8 (TARGET_LINK_LIBRARIES):
Cannot specify link libraries for target "GLBall" which is not built by
this project.
-- Configuring incomplete, errors occurred!
See also "/root/isefa/build/CMakeFiles/CMakeOutput.log".
这是我的 CMakeLists.txt
:
cmake_minimum_required(VERSION 3.0.0)
project(test C CXX)
set(CMAKE_BUILD_TYPE Release)
include_directories(include)
file(GLOB SOURCES "src/*.c")
#add_library (libtidy SHARED /usr/lib)
LINK_DIRECTORIES(/usr/lib/)
TARGET_LINK_LIBRARIES(GLBall libtidy)
add_executable(test ./bin)
install (TARGETS test DESTINATION /usr/lib)
首先你需要在 Cmake 中找到你的库(例如,这里是 Restbed 的片段):
find_library(RESTBED_LIBRARY
NAMES
restbed
PATHS
${RESTBED_ROOT}/build_release
${RESTBED_ROOT}/Release
)
if ( NOT RESTBED_LIBRARY )
message( WARNING "Restbed library NOT FOUND - the respective targets won't be build")
else()
message( STATUS "Restbed library : ${RESTBED_LIBRARY}")
endif( NOT RESTBED_LIBRARY )
我在文件夹 ${RESTBED_ROOT}/build_release 中有 librestbed.so。
然后你可以link你的目标喜欢
target_link_libraries( your_target_name ${RESTBED_LIBRARY} )
从 CMake 的角度来看,这就足够了。
我正在尝试在我的 C 项目中使用 libtidy。 我构建整洁的代码并获得 *.so 文件。 当我尝试通过 cmake 将此文件 link 添加到我的项目时,收到以下错误消息:
CMake Error at CMakeLists.txt:8 (TARGET_LINK_LIBRARIES):
Cannot specify link libraries for target "GLBall" which is not built by
this project.
-- Configuring incomplete, errors occurred!
See also "/root/isefa/build/CMakeFiles/CMakeOutput.log".
这是我的 CMakeLists.txt
:
cmake_minimum_required(VERSION 3.0.0)
project(test C CXX)
set(CMAKE_BUILD_TYPE Release)
include_directories(include)
file(GLOB SOURCES "src/*.c")
#add_library (libtidy SHARED /usr/lib)
LINK_DIRECTORIES(/usr/lib/)
TARGET_LINK_LIBRARIES(GLBall libtidy)
add_executable(test ./bin)
install (TARGETS test DESTINATION /usr/lib)
首先你需要在 Cmake 中找到你的库(例如,这里是 Restbed 的片段):
find_library(RESTBED_LIBRARY
NAMES
restbed
PATHS
${RESTBED_ROOT}/build_release
${RESTBED_ROOT}/Release
)
if ( NOT RESTBED_LIBRARY )
message( WARNING "Restbed library NOT FOUND - the respective targets won't be build")
else()
message( STATUS "Restbed library : ${RESTBED_LIBRARY}")
endif( NOT RESTBED_LIBRARY )
我在文件夹 ${RESTBED_ROOT}/build_release 中有 librestbed.so。
然后你可以link你的目标喜欢
target_link_libraries( your_target_name ${RESTBED_LIBRARY} )
从 CMake 的角度来看,这就足够了。