c++ - g++ 是否不从它存在的第一个包含路径中获取头文件?

标签 c++ g++

我正在尝试构建一个 third party tool .我对 C++ 构建工具不是很熟悉,我不确定应该如何解决这个问题。

dcp2icc.src/dcp2icc.cpp 第 6 行是:

#include "dng_camera_profile.h"

dng_sdk_1_2/dng_sdk/source/dng_camera_profile.h 第 39 行:

#include "dng_hue_sat_map.h"

两个 dng_hue_sat_map.h 文件:

$ 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

最后,这是运行的命令:

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

我预计因为 -Ifixes/dng_sdk 出现在 -Idng_sdk_1_2/dng_sdk/source 之前,所以 fixes/dng_sdk/dng_hue_sat_map.h 会是使用过,但事实并非如此:

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;
        ^~~~~~~~~~~~~~~

当头文件存在于两个包含位置时,g++如何选择使用哪个文件? include 的顺序有关系吗?如果有,影响有多大?

man g++ 简单地说:

-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.

GCC spec说以下内容,据我所知,这与我所看到的相反:

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

最佳答案

您正在使用 #include "..."形式,而不是 #include <...>形式。

文件dng_sdk_1_2/dng_sdk/source/dng_camera_profile.h包括 "dng_hue_sat_map.h" . #include "..."首先搜索相对于执行包含的文件,因此它首先在 dng_sdk_1_2/dng_sdk/source 中搜索, 无论 -I选项。

关于c++ - g++ 是否不从它存在的第一个包含路径中获取头文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42739295/

相关文章:

c++ - 针对这种情况促进代码重用

c++ - 任意大小的 DirectX9 纹理(非 2^n)

c++ - Clang 的链接器

c++ - 动态分配内存给字符指针

c++ - 交换字符数组中的字符

debugging - 使用 GCC 检测 ABI 兼容性问题

c++ - 如何在make下编译多个文件

c++ - Netbeans C++ 尝试 make.exe 的相对路径

c++ - 为什么 `pyvenv` 不安装 `python-config` ?

linux - C 程序在转换为 Windows 后显示 %zu