-4

I understand that when compiling with g++, -I is used to include header files, and -L is used to link with library files. But here is a g++ compile command from google-breakpad minidump_file_writer_unittest located at line 33:

g++ -I../ ../common/convert_UTF.c \
 ../common/string_conversion.cc \
 minidump_file_writer.cc \
 minidump_file_writer_unittest.cc \
 -o minidump_file_writer_unittest

Now what exactly does -I../ imply here? Is it including all the header files inside this directory and subdirectories?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
user1343318
  • 2,093
  • 6
  • 32
  • 59

1 Answers1

7

The -I option specifies an extra directory where the compiler should look for headers, and -I../ specifies that the extra directory is the parent directory of where the g++ command is running. Two of the source files are also found in (a sub-directory of) the parent directory. The / is optional; the compilation would work fine with -I .. instead (the space between the flag and value is also optional).

Note that the -I option says nothing (directly) about which header files are included; it just says where to look for the headers. The source code #include lines dictate which headers are included.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • Thanks Jonathan. Quick question: so it will look now in all the sub-directories under this parent directory including the parent directory for header files? Am I correct? – user1343318 Oct 28 '13 at 12:53
  • 1
    Not really. When the preprocessor sees `#include "header1.h"`, it will look for a file `../header1.h` before going on to look in other standard locations. If it sees `#include "subdir/header2.h"`, it will look for a file `../subdir/header2.h` before going on to look in other standard locatins. If perchance it sees [`#include "../other/header3.h"`](http://stackoverflow.com/q/597318/), it will look for a file `../../other/header3.h` before looking in other places. Generally, with the `"header.h"` notation, it will look in the current directory first; for the `` notation, it won't. – Jonathan Leffler Oct 28 '13 at 13:51