Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does my C++ compiler look to resolve my #includes?

Tags:

c++

this is a really basic question. I've been learning C++ and thus far I have only used the standard library. I have been including things like <iostream> and with no problems. Now I want to use Apache Xerces, so I've installed it on my machine (a Debian system) and am following a tutorial which says I need to include:

#include <xercesc/sax2/SAX2XMLReader.hpp>

but g++ says "error: xercesc/sax2/SAX2XMLReader.hpp: No such file or directory". Where is it looking? Do I need to give it more information?

Thanks.

like image 806
ghallio Avatar asked Jan 23 '10 15:01

ghallio


1 Answers

Use the --verbose option:

[...]
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/i686-pc-linux-gnu/4.4.2/../../../../include/c++/4.4.2
 /usr/lib/gcc/i686-pc-linux-gnu/4.4.2/../../../../include/c++/4.4.2/i686-pc-linux-gnu
 /usr/lib/gcc/i686-pc-linux-gnu/4.4.2/../../../../include/c++/4.4.2/backward
 /usr/local/include
 /usr/lib/gcc/i686-pc-linux-gnu/4.4.2/include
 /usr/lib/gcc/i686-pc-linux-gnu/4.4.2/include-fixed
 /usr/include
End of search list.
[...]

You can use the -I option to add search directories, as explained here: http://gcc.gnu.org/onlinedocs/gcc-4.4.3/gcc/Directory-Options.html#Directory-Options

You can also use environment variables to change this permanently: http://gcc.gnu.org/onlinedocs/gcc-4.4.3/gcc/Environment-Variables.html#Environment-Variables
In your case, you could use CPLUS_INCLUDE_PATH.

like image 113
Bastien Léonard Avatar answered Sep 30 '22 19:09

Bastien Léonard