在 cmake 中包含头文件

标签 include cmake

我有一个 CMakeList.txt 文件,它只有一个衬垫include(startevn.cmake)在 startevn.cmake 我有,

project(startevn)
set(headers 
   startup.h
)
set(sources
  system-init.cpp
)
new_library(startevn ${sources} ${headers})

现在我必须将启动移动到不同的目录。这样做之后我添加了
以下行到“startevn.cmake”,
include_directories("/new_folder_location/sub_folder")

sub_folder 是 startup.h 现在所在的位置,但编译器仍然说
找不到源文件:startup.h。
我究竟做错了什么?

最佳答案

导致之前的代码:
new_library(startevn ${sources} ${headers})
它确实告诉了图书馆的位置,

但之后,你的 include_directories()也许不是。

尝试:

set(INCLUDE_DIR /new_folder_location/sub_folder)
include_directories (${INCLUDE_DIR})     # make sure your .h all inside.

(或者之前需要使用 cmake 的 find_library() 来检查它是否正确找到。)

关于在 cmake 中包含头文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17721101/

相关文章:

c++ - 如何强制 cmake 链接 Homebrew 桶专用库

c++ - 如何将 boost 库包含到 C++ 程序中?

c# - 在 C# 中编译包含重新定义的架构

c - 如何在 Qt Creator 中为 Clang 静态分析器设置语言标准 (-std)

cmake - 将所有文件安装在目录中,除了 CMake 中的文件夹

c++ - 将 cmake 用于具有子/外部项目/依赖项的项目

c++ - Cmake 错误 : variables NOTFOUND when configuring or building openpose on windows 10

c# - 从单独的源文件 (ASP.NET/C#) 插入代码

Django 包含标签不起作用

php - 使用 php 更改目录中当前文件的动态 url 路径