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 -nostdinc
flag 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?
it's simple, use the "-B" option to add . h files' dir to search path. Show activity on this post. Headers included with #include <> will be searched in all default directories , but you can also add your own location in the search path with -I command line arg.
Look at Preferences->Locations->"Custom Paths" in Xcode's preference. A path added here will be a variable which you can add to "Header Search Paths" in project build settings as "$cppheaders", if you saved the custom path with that name. Set HEADER_SEARCH_PATHS parameter in build settings on project info.
Most standard headers are stored in /usr/include . It looks like stdbool. h is stored somewhere else, and depends on which compiler you are using. For example, g++ stores it in /usr/include/c++/4.7.
GCC looks for headers requested with #include " file " first in the directory containing the current file, then in the directories as specified by -iquote options, then in the same places it would have looked for a header requested with angle brackets. For example, if /usr/include/sys/stat.
The search paths for includes are taken in the following order:
-I
command-line option.CPLUS_INCLUDE_PATH
environment variable.So, you can use either of the first two (whichever seems better/more convenient for your purposes).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With