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.
The two forms of the #include directive are summarized fairly well by MSDN:
Also see this (duplicate/similar) question (for G++/GCC):
C++ #include semantics
Use the
--verbose
option: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-OptionsYou 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
.To tell g++ where to look (apart from its defaults), you use the -I flag:
tells it to look in the /foo/bar directory and construct paths from there. You can use multiple -I flags to specify multiple start points for the compiler to start looking.
On my rather old Windows system, Xerces is installed in /xerces, so I set up an include flag:
Which allows me to say things like:
to include the file:
The C++ Standard says in 16.2/2
The implementation-defined means that where and headers are searched and how headers location should be specified is specific to particular compiler. In fact, it is possible implementations may not use a one header in one file convention, but some fancy packaging systems, for instance all a library is supposed to ship headers in .zip archive location of such archive is given to compiler, then compiler takes care of extracting headers from it, etc.
What it means is that you are supposed to check documentation of compiler you are using for details about how to specify so called include directories, location of headers.
In case of GCC compiler, use -I option - see Options for Directory Search in the manual for details. You can also use C_INCLUDE_PATH or CPLUS_INCLUDE_PATH environment variables.
Related question is How to add a default include path for gcc in linux?
In order to use a new library, only specifying the header file is not enough. You may also need to specify the related library defined in the header file by using -l[library name] and -L[library path] you want to be linked in your gcc commend.
For the difference between header file and library, please check this post: What are Header Files and Library Files?
Gcc usually starts looking for include files in /usr/include. If you have include files in other directories, you can add a -I option to the command line to tell the compiler to look there also.
You might have to install the development package for Xerces to get the #include files.