将外部库添加到CMakeList.txt c ++ [英] Add external libraries to CMakeList.txt c++
问题描述
我有我的外部库,如下图所示,我创建后的符号链接:
https://imagizer.imageshack.us/v2/682x472q90/840/pn.png
以及与其他文件中的库相关的标题:
https://imagizer.imageshack.us/v2/682x374q90/855/tjrh.png
我使用ROS,我需要添加这些库到我的包到CmakeList.txt:
cmake_minimum_required(VERSION 2.4.6)
include($ ENV {ROS_ROOT } /bt/rosbuild/rosbuild.cmake)
rosbuild_init()
#set构建可执行文件到bin目录的默认路径
set(EXECUTABLE_OUTPUT_PATH $ {PROJECT_SOURCE_DIR} / bin)
#设置构建库到lib目录的默认路径
set(LIBRARY_OUTPUT_PATH $ {PROJECT_SOURCE_DIR} / lib)
#common命令用于构建c ++可执行文件和库
#rosbuild_add_library($ {PROJECT_NAME} src / example.cpp)
#target_link_libraries($ {PROJECT_NAME} another_library)
#rosbuild_add_boost_directories()
#rosbuild_link_boost ($ {PROJECT_NAME} thread)
#rosbuild_add_executable(example example / example.cpp)
#target_link_libraries(example $ {PROJECT_NAME})
rosbuild_add_executable(kinectueye src / kinect_ueye.cpp )
所以我的问题是如何添加这些文件夹(我认为我需要的第一个添加我不确定)到我的CmakeList.txt文件,以便我可以使用我的程序中的类和方法。
谢谢。 b $ b
我将从升级CMAKE版本开始。
=http://www.cmake.org/cmake/help/v2.8.12/cmake.html#command%3ainclude_directories> INCLUDE_DIRECTORIES 的标题位置和 LINK_DIRECTORIES + TARGET_LINK_LIBRARIES for libraries
INCLUDE_DIRECTORIES(your / header / dir)
$请注意
LINK_DIRECTORIES(您的/ library / dir)
rosbuild_add_executable(kinectueye src / kinect_ueye.cpp)
TARGET_LINK_LIBRARIES(kinectueye lib1 lib2 lib2 ...)
lib1
已扩展为liblib1.so
<$ c $ p>
$ b < (在Linux上),因此使用ln 创建适当的链接(如果您没有这些链接)I have my extern library as shown in this picture that I create the symbolic links after:
https://imagizer.imageshack.us/v2/682x472q90/840/pn.png
and the headers related to the library in other file:
https://imagizer.imageshack.us/v2/682x374q90/855/tjrh.png
I working with ROS and I need to add these libraries to my package to CmakeList.txt:
cmake_minimum_required(VERSION 2.4.6) include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake) rosbuild_init() #set the default path for built executables to the "bin" directory set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) #set the default path for built libraries to the "lib" directory set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) #common commands for building c++ executables and libraries #rosbuild_add_library(${PROJECT_NAME} src/example.cpp) #target_link_libraries(${PROJECT_NAME} another_library) #rosbuild_add_boost_directories() #rosbuild_link_boost(${PROJECT_NAME} thread) #rosbuild_add_executable(example examples/example.cpp) #target_link_libraries(example ${PROJECT_NAME}) rosbuild_add_executable(kinectueye src/kinect_ueye.cpp)
So my question is how can I add these folders (I think the first one that I need to add I'm not sure) to my CmakeList.txt file so as I can use the classes and the methods in my program.
Thank you.
解决方案I would start with upgrade of CMAKE version.
You can use INCLUDE_DIRECTORIES for header location and LINK_DIRECTORIES + TARGET_LINK_LIBRARIES for libraries
INCLUDE_DIRECTORIES(your/header/dir) LINK_DIRECTORIES(your/library/dir) rosbuild_add_executable(kinectueye src/kinect_ueye.cpp) TARGET_LINK_LIBRARIES(kinectueye lib1 lib2 lib2 ...)
note that
lib1
is expanded toliblib1.so
(on Linux), so use ln to create appropriate links in case you do not have them这篇关于将外部库添加到CMakeList.txt c ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!