[英]added subdirectory to CMakeLists.txt isn't detected by main.cpp
I'm working on creating a python binding to a c++ code using Pybind11.我正在使用 Pybind11 创建到 C++ 代码的 python 绑定。 My project architecture is the following:
我的项目架构如下:
-- MyProject
| -- lib
| -- pybind11
| -- CMakeLists.txt
| -- include
| -- myCPPCode
| -- CMakeLists.txt
| -- MyCodeDefinitions.h
| -- MyCode.cpp
| -- src
| -- MyProject
| -- MyModule.cpp
| -- CMakeLists.txt
| -- setup.py
what I want to do, is to include #include <myCPPCode/MyCodeDefinitions.h>
into MyModule.cpp
.我想要做的是将
#include <myCPPCode/MyCodeDefinitions.h>
到MyModule.cpp
。
In order to do that, I added into the global CMakeLists.txt
the following command: add_subdirectory(lib/myCPPCode)
, But it's not working, as I don't know what to put in lib/myCPPCode/CMakeLists.txt
, and I'm getting the following error:为了做到这一点,我在全局
CMakeLists.txt
添加了以下命令: add_subdirectory(lib/myCPPCode)
,但它不起作用,因为我不知道在lib/myCPPCode/CMakeLists.txt
放什么,我收到以下错误:
path/MyProject/src/MyProject/MyModule.cpp:2:10: fatal error: myCPPCode/MyCodeDefinitions.h: No such file or directory
2 | #include <myCPPCode/MyCodeDefinitions.h>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
The content of lib/myCPPCode/CMakeLists.txt
is the following: lib/myCPPCode/CMakeLists.txt
的内容如下:
cmake_minimum_required(VERSION 3.13)
project(myCPPCode)
add_library(myCPPCode MyCode.cpp)
How should I configure my CMakeLists.txt
and lib/myCPPCode/CMakeLists.txt
?我应该如何配置我的
CMakeLists.txt
和lib/myCPPCode/CMakeLists.txt
?
Thank you in advance!先感谢您!
The add_subdirectory
just tells cmake to find a CMakeLists.txt in the directory given as argument. add_subdirectory
只是告诉 cmake 在作为参数给出的目录中找到 CMakeLists.txt。
You need to change your add_subdirectory(lib/myCPPCode)
into include_directories(lib/myCPPCode)
and it should work better.您需要将
add_subdirectory(lib/myCPPCode)
更改为include_directories(lib/myCPPCode)
并且它应该会更好地工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.