为什么 cmake 许可证<>样式不包括?
Why won't cmake permit <> style include?
我对cmake很陌生,但我在Visual Studio上使用它来开发一个必须在linux上运行的程序。我需要以这种方式包括以下内容:
#include <xscontroller/xscontrol_def.h>
#include <xscontroller/xsdevice_def.h>
#include <xscontroller/xsscanner.h>
#include <xstypes/xsoutputconfigurationarray.h>
#include <xstypes/xsdatapacket.h>
#include <xstypes/xstime.h>
#include <xscommon/xsens_mutex.h>
然而,只有当我执行以下操作时,visualstudio才能识别这些文件:
#include "xscontroller/xscontrol_def.h"
#include "xscontroller/xsdevice_def.h"
#include "xscontroller/xsscanner.h"
#include "xstypes/xsoutputconfigurationarray.h"
#include "xstypes/xsdatapacket.h"
#include "xstypes/xstime.h"
#include "xscommon/xsens_mutex.h"
我在VS中的项目结构相当简单:
ANT
-out
-xscommon
-xscontroller
-xstypes
-ANT.cpp
-CMakeLists.txt
.
.
.
我需要的includes在three-xs文件夹中,我相信它们必须用<gt;无论是在visualstudio中还是在linux上编译代码时,因为每个头中的引用都是在<gt;表单,这就是导致此错误的原因:
xscallbackplainc.h:68:10: fatal error: xstypes/pstdint.h: No such file or directory
#include <xstypes/pstdint.h>
^~~~~~~~~~~~~~~~~~~
在编译时。
简单地说,我真的只需要知道什么命令(无论是在CMakeLists.txt中还是在其他地方(将允许在项目中和在linux上通过ssh编译的项目中进行这种引用。我知道#include ""
和#include <>
之间的区别,但我是cmake的新手,到处找都找不到答案。
实现这一点的最简单方法是使用include_directories
命令。只需将以下内容添加到您的ANT/CMakeLists.txt
:
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
尽管我强烈建议使用target_include_directories()
。两者的区别在于target_include_directories()
仅为一个目标[1]指定了包含目录。
[1] 。目标是通过add_executable()
或add_library()
:指定的任何内容
cmake_minimum_required(VERSION 3.12)
project(ANT)
add_executable(ANT ANT.cpp) #other source files as necessary
#format of target_include_directories:
# target_include_directories(target_name PUBLIC|PRIVATE PATH_TO_DIR)
target_include_directories(ANT PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
我已经发布了关于链接的问题,希望它有意义。应该清楚我不知道自己在做什么。
相关文章:
- 为什么 cmake 许可证<>样式不包括?
- 计算平均值,不包括上次得分
- 将值从另一个数组写入数组,不包括不需要的值 C++
- 如果语句不包括文本行?
- 找到 x^n 的所有组合,并检查它们的总和是否等于一个不包括相同数字的数字
- 如何保证不包括 iostream?
- 创建一个循环,该循环将输出大于零且小于 60(不包括 60)的所有 5 的倍数
- C/C++ 经过的流程周期,不包括断点处
- 回文,不包括特殊字符和空格
- 查找 n 个数字的公因数数(不包括"1"作为公因数)
- 在 C++ 中的 SetClipboardData() 之后粘贴不包括记事本的换行符
- C++11 exit() 和 abs() 不包括 <cstdlib>?
- 生成生成 makefile 时不包括 cmake C++11 标志
- 寻找一种单一的定时方法来测试各种算法,不包括它们的输入
- 提升正则表达式 cpp 用于查找 %% 之间的字符串,输出不包括 % 字符本身
- gSoap 不包括信封和正文开始标签
- 与不包括一个标头更好的使用不完整的标头比另一个标头的使用无效
- 在不包括任何内容的情况下获得错误声音
- 运行单元测试不包括Catch2中的特定标签
- c4710 功能不包括在内 std::basic_ostream