l0b0 l0b0 - 9 months ago 59
C++ Question

Does g++ not take header files from the first include path it exists in?

I'm trying to build a third party tool. I'm not very familiar with the C++ build tools, and I'm not sure how this should be resolved.

line 6 is:

#include "dng_camera_profile.h"

line 39:

#include "dng_hue_sat_map.h"

There are two

$ ls -l dng_sdk_1_2/dng_sdk/source/dng_hue_sat_map.h fixes/dng_sdk/dng_hue_sat_map.h
-r--r--r-- 1 user users 3141 Apr 9 2008 dng_sdk_1_2/dng_sdk/source/dng_hue_sat_map.h
-rw-r--r-- 1 user users 3124 Oct 31 2015 fixes/dng_sdk/dng_hue_sat_map.h

Finally, this is the command which gets run:

g++ -o build/dcp2icc/dcp2icc.o -c -m32 -O2 -iquote- -DUNIX_ENV=1 -D_FILE_OFFSET_BITS=64 -DkBigEndianHost=0 -Idcp2icc.src -Ifixes/dng_sdk -Idng_sdk_1_2/dng_sdk/source -INone dcp2icc.src/dcp2icc.cpp

I expected that because
comes before
would be used, but this is not the case:

In file included from dng_sdk_1_2/dng_sdk/source/dng_camera_profile.h:39:0,
from dcp2icc.src/dcp2icc.cpp:6:
dng_sdk_1_2/dng_sdk/source/dng_hue_sat_map.h:129:8: error: extra qualification 'dng_hue_sat_map::' on member 'operator==' [-fpermissive]
bool dng_hue_sat_map::operator== (const dng_hue_sat_map &rhs) const;

How does g++ choose which file to use when the header file exists in two include locations? Does it matter which sequence the
s are in, and if so, how?

man g++
simply has this to say:

-I dir

Add the directory dir to the list of directories to be searched for header files. Directories named by -I are searched before the standard system include directories. If the directory dir is a standard system include directory, the option is ignored to ensure that the default search order for system directories and the special treatment of system headers are not defeated . If dir begins with "=", then the "=" will be replaced by the sysroot prefix; see --sysroot and -isysroot.

The GCC spec says the following, which as far as I can tell is the opposite of what I'm seeing:

You can specify multiple -I options on the command line, in which case the directories are searched in left-to-right order.

hvd hvd
Answer Source

You're using the #include "..." form, rather than the #include <...> form.

The file dng_sdk_1_2/dng_sdk/source/dng_camera_profile.h is including "dng_hue_sat_map.h". #include "..." first searches relative to the file doing the including, so it first searches in dng_sdk_1_2/dng_sdk/source, regardless of -I options.