将外部库添加到 CMakeList.txt C++
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24570916/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Add external libraries to CMakeList.txt c++
提问by Ja_cpp
I have my external library as shown in this picture that I create the symbolic links after:
我有我的外部库,如图所示,我在之后创建符号链接:
and the headers related to the library in other file:
以及与其他文件中的库相关的标题:
I'm working with ROS ubuntuand I need to add these libraries to my package to CmakeList.txt:
我正在使用ROS ubuntu,我需要将这些库添加到我的包中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.txtfile so as I can use the classes and the methods in my program.
所以我的问题是如何将这些文件夹(我认为我需要添加的第一个文件夹我不确定)添加到我的CmakeList.txt文件中,以便我可以在我的程序中使用这些类和方法。
回答by Peter
I would start with upgrade of CMAKE version.
我将从升级 CMAKE 版本开始。
You can use INCLUDE_DIRECTORIESfor header location and LINK_DIRECTORIES+ TARGET_LINK_LIBRARIESfor libraries
您可以使用INCLUDE_DIRECTORIES作为标题位置,使用LINK_DIRECTORIES+ TARGET_LINK_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 lib1is expanded to liblib1.so(on Linux), so use lnto create appropriate links in case you do not have them
请注意,它lib1已扩展为liblib1.so(在 Linux 上),因此如果您没有它们,请使用 ln创建适当的链接


