C 预处理器包含和路径
C preprocessor include and paths
假设我们有一个 .cpp
文件 A
包括一个 .h
文件 B
其中包括一个 .h
文件 C
.
// File A.cpp
#include "B.h"
...
// File B.h
#include "../../utilityies/C.h"
...
如果 B
使用相对路径包含 C
,相对路径是相对于 B
的位置还是相对于 A
的位置解析的.cpp
B
将被复制粘贴到 ?
包含路径是相对于包含它的文件的,因此在您的情况下是相对于 B 的位置。
来自gcc docs:
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.h contains #include "types.h", GCC looks for
types.h first in /usr/include/sys, then in its usual search path.
假设我们有一个 .cpp
文件 A
包括一个 .h
文件 B
其中包括一个 .h
文件 C
.
// File A.cpp
#include "B.h"
...
// File B.h
#include "../../utilityies/C.h"
...
如果 B
使用相对路径包含 C
,相对路径是相对于 B
的位置还是相对于 A
的位置解析的.cpp
B
将被复制粘贴到 ?
包含路径是相对于包含它的文件的,因此在您的情况下是相对于 B 的位置。
来自gcc docs:
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.h contains #include "types.h", GCC looks for types.h first in /usr/include/sys, then in its usual search path.