I have a c++ project having two src folders. Source file in folder 1 may need to include header file in src folder 2. Is it possible? or how should I write my Makefiles? thanks
我有一个c ++项目有两个src文件夹。文件夹1中的源文件可能需要在src文件夹2中包含头文件。是否可能?或者我该如何写我的Makefile?谢谢
2 个解决方案
#1
30
Depending on how closely the two folders are related (eg, if they're the same project), then it can be as easy as:
根据两个文件夹的相关程度(例如,如果它们是同一个项目),它可以像以下一样简单:
#include "../otherfolder/header.h"
If they're separate projects, then it's customary to simply add the other project's header directory to your project's header search path, and include the header like this:
如果它们是单独的项目,那么习惯上只需将其他项目的头文件目录添加到项目的标题搜索路径中,并包含如下标题:
#include <header.h>
(In practice, the brackets/quotes don't matter, but it helps keep external vs. internal header imports separate)
(实际上,括号/引号无关紧要,但它有助于保持外部与内部标题导入分开)
#2
3
Considering you have src1 and src2 folders in same folder. You have 2 solutions for this:
考虑到你在同一文件夹中有src1和src2文件夹。你有2个解决方案:
1 - #include "../src2/header.h"
1 - #include“../src2/header.h”
2 - Add in your project at additional include directories src2 and use normal #include
2 - 在项目中添加其他包含目录src2并使用普通的#include
#1
30
Depending on how closely the two folders are related (eg, if they're the same project), then it can be as easy as:
根据两个文件夹的相关程度(例如,如果它们是同一个项目),它可以像以下一样简单:
#include "../otherfolder/header.h"
If they're separate projects, then it's customary to simply add the other project's header directory to your project's header search path, and include the header like this:
如果它们是单独的项目,那么习惯上只需将其他项目的头文件目录添加到项目的标题搜索路径中,并包含如下标题:
#include <header.h>
(In practice, the brackets/quotes don't matter, but it helps keep external vs. internal header imports separate)
(实际上,括号/引号无关紧要,但它有助于保持外部与内部标题导入分开)
#2
3
Considering you have src1 and src2 folders in same folder. You have 2 solutions for this:
考虑到你在同一文件夹中有src1和src2文件夹。你有2个解决方案:
1 - #include "../src2/header.h"
1 - #include“../src2/header.h”
2 - Add in your project at additional include directories src2 and use normal #include
2 - 在项目中添加其他包含目录src2并使用普通的#include