How to make g++ search for header files in a specific directory?

Posted by Bane on Stack Overflow See other posts from Stack Overflow or by Bane
Published on 2012-09-29T15:29:56Z Indexed on 2012/09/29 15:37 UTC
Read the original article Hit count: 271

Filed under:
|
|
|
|

I have a project that is subdivided into a few directories with code in them. I'd like to to have g++ search for header files in the project's root directory, so I can avoid different include paths for same header files across multiple source files.

Mainly, the root/ directory has sub-directories A/, B/ and C/, all of which have .hpp and .cpp files inside. If some source file in A wanted to include file.hpp, which was in B, it would have to do it like this: #include "../B/file.hpp". Same for another source file that was in C. But, if A itself had sub-directories with files that needed file.hpp, then, it would be inconsistent and would cause errors if I decided to move files (because the include path would be "../../B/file.hpp").

Also, this would need to work from other projects as well, which reside outside of root/. I already know that there is an option to manually copy all my header files into a default-search directory, but I'd like to do this the way I described.

© Stack Overflow or respective owner

Related posts about linux

Related posts about compiler