将外部库添加到CMakeList.txt c ++

时间:2014-07-04 09:22:52

标签: c++ cmake libraries

我有我的外部库,如下图所示,我创建了符号链接:

enter image description here

以及与其他文件中的库相关的标题:

enter image description here

我正在使用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)

所以我的问题是如何将这些文件夹(我认为我需要添加的第一个我不确定)添加到我的CmakeList.txt文件中,以便我可以使用我的类和方法程序

1 个答案:

答案 0 :(得分:56)

我会从升级CMAKE版本开始。

您可以使用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 ...)

请注意,lib1已扩展为liblib1.so(在Linux上),因此如果您没有use ln,则{{3}}可以创建适当的链接