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++
基础教程推荐
- Windows Media Foundation 录制音频 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 从 std::cin 读取密码 2021-01-01