0

I'm not an expert and I do coding mainly for fun every now and then, so please don't laugh if this question is stupid (I know it is), but I simply don't understand how includes work.

I have about 8 directories where my header files are located, also each of these 'root' directories have at least 10 subdirectories with additional header files and so on. (these are system headers and my own)

Do I have to head my compiler to every single sub directory or is it just enough to specify a 'root' directory using '-I' compiler option (or trough PATH environment variable) ?

I'm confused wether to include all 50+ possible paths combinations to header files ^^ it just seems not logical.

1
  • IMHO it would be good style to specify only the path to the 'root directories' with the -I option and to specify subpathes from there relative in the #include statement: #include "root/sub/myheader.h" Commented Jun 30, 2014 at 10:10

1 Answer 1

1

If you just -I the root directory, then your #include will have to be something like:

#include "subdir1/anincludefile.h"
Sign up to request clarification or add additional context in comments.

2 Comments

That seems logical from programmers perspective, but how does other libraries such as GTK, system headers or boost lib's find them selfs then? if only root is specified?
@codekiddy 'but how does ... boost lib's find them selfs then?' They do the same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.