Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何为这种不寻常的头结构编写我的CMakeLists.txt? 我试图为C++中的项目编写一个代码> CMAKLIST.TXT ,这取决于几个第三方库。其中一个库(对我来说)在包含如下所述的头文件时遵循一种不寻常的模式_C++_Cmake - Fatal编程技术网

如何为这种不寻常的头结构编写我的CMakeLists.txt? 我试图为C++中的项目编写一个代码> CMAKLIST.TXT ,这取决于几个第三方库。其中一个库(对我来说)在包含如下所述的头文件时遵循一种不寻常的模式

如何为这种不寻常的头结构编写我的CMakeLists.txt? 我试图为C++中的项目编写一个代码> CMAKLIST.TXT ,这取决于几个第三方库。其中一个库(对我来说)在包含如下所述的头文件时遵循一种不寻常的模式,c++,cmake,C++,Cmake,我的代码结构如下: project/ - CMakeLists.txt - src/ - main.cpp - lib/ - CMakeLists.txt - moduleA/ -CMakeLists.txt - fooA.cpp - fooA.h - barA.cpp - barA.h - moduleB/ - CMakeLists.txt

我的代码结构如下:

project/
  - CMakeLists.txt
  - src/
    - main.cpp
  - lib/
    - CMakeLists.txt
    - moduleA/
        -CMakeLists.txt
        - fooA.cpp
        - fooA.h
        - barA.cpp
        - barA.h
    - moduleB/
        - CMakeLists.txt
        - fooB.cpp
        - fooB.h
moduleA
取决于
moduleB
,此外
fooA
还取决于
barA
。问题在于
include
fooA.cpp
barA.cpp
的声明:

//fooA.cpp
#包括“模块a/fooA.h”
#包括“模块a/barA.h”
...
同样适用于
barA.cpp
。当我在
cmake
之后运行
make
时,它抱怨在编译
fooA.cpp
时找不到
moduleA/fooA.h
。我不确定如何在
moduleA
中包含这些文件,或者我应该在哪个
CMakeLists.txt
中包含这些文件<代码>模块B正确编译。我无法更改库的代码,但可以添加
cmake
文件

lib
中的My
CMakeLists.txt
moduleA
中的
CMakeLists.txt
如下所示

# lib/CMakeLists.txt
cmake_minimum_required(VERSION 3.1...3.14)
project(mylibs VERSION 1.0.0 LANGUAGES CXX)
add_subdirectory(moduleA)
add_subdirectory(moduleB)

错误本质上是编译器在编译
moduleA
源代码时没有找到
moduleA
头,因为
moduleA
源文件以一种不同寻常的方式(对我来说)将头包含在同一目录中,
包含“moduleA/header”
包含目录(…)
可以做你想做的事。这种不寻常的头文件结构我认为这是一种非常常见的头文件结构。@drescherjm如果头文件与源文件位于同一目录中,我习惯于在
#include
语句中不包含目录名,所以这对我来说是不寻常的。我应该在
CMakeLists.txt
中添加
include_目录(..)
?我会在
lib/CMakeLists.txt中添加一个
add_库(lib接口)
target_include_目录(lib接口)
并链接到该库。但是您可以只
target\u include\u目录(moduleA PUBLIC${CMAKE\u CURRENT\u SOURCE\u DIR}/)
。一个添加新的接口库,另一个将include目录添加到moduleA库。Cmake相当冗长,当您开始按拼写读取函数时。首先,我需要将moduleA和moduleB与接口库链接起来。
#moduleA/CMakeLists.txt
cmake_minimum_required(VERSION 3.1...3.14)
project(moduleA VERSION 1.0.0 LANGUAGES CXX)
set (SOURCES fooA.cpp barA.cpp)
set (HEADERS fooA.h barA.h)
add_library(moduleA STATIC ${SOURCES} ${HEADERS})
target_link_libraries(moduleA PUBLIC moduleB)