问题
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