4

GCC has built in include directories for certain standard headers. I just need to know where this list is. My newly compiled gcc will not compile my little test C++ program because it cannot find standard headers. I think it fails because of some config options I used to make my file system more organized. I set the bindir and libdir, which I think might have screwed up the built-in include paths for some reason.

Program (dummy.c):

#include <iostream>
void main(){}

Command:

g++ dummy.c

Error:

dummy.c:1:20: fatal error: iostream: No such file or directory
Charles
  • 165
  • 1
  • 6

1 Answers1

4

The preprocessor can tell you what it uses

cpp -x c++ -v

...

    #include "..." search starts here:
    #include <...> search starts here:
     /usr/include/c++/4.4
     /usr/include/c++/4.4/i486-linux-gnu
     /usr/include/c++/4.4/backward
     /usr/local/include
     /usr/lib/gcc/i486-linux-gnu/4.4.1/include
     /usr/lib/gcc/i486-linux-gnu/4.4.1/include-fixed
     /usr/include/i486-linux-gnu
     /usr/include
    End of search list.

You can add directories to the search path by setting the C_INCLUDE_PATH and/or CPLUS_INCLUDE_PATH environment variiables

user9517
  • 114,104
  • 20
  • 206
  • 289
  • ah great, I was looking for some way to actually print those out. Now I know for certain that they are screwed up. – Charles Jun 02 '10 at 21:09
  • 1
    It appears that later versions of gcc don't have a default specs file to read from, but can generate one for later customisation. There is more discussion about this [here](http://stackoverflow.com/questions/558803/how-to-add-a-default-include-path-for-gcc-in-linux) – user9517 Jun 03 '10 at 09:02
  • I made some customizations to my specs file to add the real include directories and I can now compile. Usually I would not let such a hack fly but this is a temp toolchain anyway, thanks! – Charles Jun 03 '10 at 13:42