I’m currently trying to get a program to compile on a system that I don’t have control over.
The problem that I’m having is the include directories look like this:
/usr/include:
gmpxx.h gmp.h
/usr/local/include:
gmp.h
In my cpp file, I use
#include <gmpxx.h>
and this finds the correct file in /usr/include, however when gmpxx.h includes gmp.h, it pulls it from /usr/local/include, which breaks the build.
Right now, I see 3 very ugly solutions to the problem
-
In my cpp file, add
#include </usr/include/gmp.h>
Having an absolute include path is pretty ugly and non-portable, and I think that this sort of thing should belong in the Makefile instead of the source. -
add the
-nostdincflag to my makefile, and specify the include paths by hand -
create local symlinks to the libraries that I really want, and then do local includes (
#include "gmp.h")
Is there a better solution that I’m missing?
The search paths for includes are taken in the following order:
-Icommand-line option.CPLUS_INCLUDE_PATHenvironment variable.So, you can use either of the first two (whichever seems better/more convenient for your purposes).