how to include header files in other src folder

↘锁芯ラ 提交于 2021-02-15 10:50:36

问题


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


回答1:


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:


Considering you have src1 and src2 folders in same folder. You have 2 solutions for this:

1 - #include "../src2/header.h"

2 - Add in your project at additional include directories src2 and use normal #include



来源:https://stackoverflow.com/questions/5134357/how-to-include-header-files-in-other-src-folder

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!