cmake 目录包含 引入头文件 问题

有如下目录结构
common/saybye.h
common/saybye.cpp
common/sayhello.h
common/sayhello.cpp
main/main.cpp

src下包含两个目录
main
common

其中main.cpp 中内容如下

#include
#include"common/saybye.h"
#include"common/sayhello.h"
using namespace std;
int main()
{
sayhello();
saybye();
}

<

pre>
saybye.cpp文件中实现saybye()函数
sayhello.cpp 文件中实现sayhello()函数

现在问题是: 现在我不想将main.cpp 的
#include"common/saybye.h"
#include"common/sayhello.h"
改为
#include"../common/saybye.h"
#include"../common/sayhello.h"

实际上是我用CLIon 到如oceanbase 代码是,main()函数在一个子目录下,common子目录下包含很多库,直接导入 main函数中很多头文件不能找到。oceanbase 使用auto-make 的。
请问如何写CMAKELists.txt?

阅读 18.7k
2 个回答

你需要添加include目录.

在你的CMakeLists.txt中用include_directories来设置common/saybye.hcommon/sayhello.h的目录,这样就能直接include了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题