Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++: #include file search?

This MSDN document quotes:

look for include files in the same directory of the file that contains the #include statement, and then in the directories of any files that include (#include) that file

Wait, what?
What does that actually mean (the bold stuff)?

like image 265
shoosh Avatar asked Jul 28 '26 03:07

shoosh


1 Answers

It probably means that if foo/bar/baz.c includes ../bog/bog.h, and the latter contains

#include "fix.h"

it would find foo/bar/fix.h. In other words, it looks in the directory that contained the C file that included the header containing the include. Clear? :)

So, the file layout rendered as gorgeous ASCII graphics, is:

  foo/
  |
  +-bar/
  | |
  | +-baz.c
  | |
  | +-fix.h
  |
  +-bog/
    |
    +-bog.h

And bog.h is then able to find fix.h in the sibling directory foo.

like image 137
unwind Avatar answered Jul 29 '26 16:07

unwind



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!