Add external libraries to CMakeList.txt c++(将外部库添加到 CMakeList.txt C++)
问题描述
我有我的外部库,如下图所示,我在之后创建符号链接:
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:
我正在使用 ROS ubuntu,我需要将这些库添加到我的包中到 CmakeList.txt:
I'm working with ROS ubuntu 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)
所以我的问题是如何将这些文件夹(我认为我需要添加的第一个文件夹我不确定)添加到我的 CmakeList.txt 文件中,以便我可以使用这些类以及我程序中的方法.
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.
推荐答案
我会从升级 CMAKE 版本开始.
I would start with upgrade of CMAKE version.
您可以使用 INCLUDE_DIRECTORIES 作为标题位置和 LINK_DIRECTORIES + TARGET_LINK_LIBRARIES 图书馆
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 ...)
注意 lib1 被扩展为 liblib1.so(在 Linux 上),所以 使用 ln 创建适当的链接,以防您没有它们
note that lib1 is expanded to liblib1.so (on Linux), so use ln to create appropriate links in case you do not have them
这篇关于将外部库添加到 CMakeList.txt C++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将外部库添加到 CMakeList.txt C++
基础教程推荐
- CString 到 char* 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 初始化列表*参数*评估顺序 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
