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

标签 c++ cmake libraries

我有我的外部库,如图所示,我在之后创建符号链接(symbolic link):

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 文件中,以便我可以使用这些类以及我程序中的方法。

最佳答案

我会从升级 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创建适当的链接以防万一您没有它们

关于c++ - 将外部库添加到 CMakeList.txt c++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24570916/

相关文章:

c++ - 为什么 CMake 被设计为在安装时删除运行时路径

c - 使用 cfitsio 库编译代码时 undefined reference

android - Android 上的 NEON 优化库

c++ - LLDB:通过控制台为malloc_error_break设置断点

c++ - 在 Cmake 中将 flto=jobserver 传递给 gcc

c++ - 在 C++ 中写入二进制数据

assembly - 如何使用 Cmake 用 NASM 构建二进制文件

c - 如何处理静态链接库之间的符号冲突?

c++ - 将指向模板函数的指针作为函数参数传递?

c++ - "return std::move(*this);"有什么不正确的地方吗?