c++ - c++ 中的预处理和搜索路径如何工作?
问题描述
我有一个 clang.C 文件:
#include "A.h"
#include "B.h"
int main(int argc, char* argv[])
{
return 1;
}
我还有这些包含路径,它们将按顺序传递给编译器参数:
/path/to/B.h
/path/to/A.h
/different/path/to/B.h <-- duplicate file
当我将所有 3 条路径(按顺序)添加到我的预处理器语句并运行它时,我得到了这个:
# 1 "clang.C"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "<command-line>" 2
# 1 "clang.C"
# 1 "/path/to/A.h" 1
# 2 "clang.C" 2
# 1 "/path/to/B.h" 1
# 3 "clang.C" 2
int main(int argc, char* argv[])
{
return 1;
}
我希望该/path/to/B.h
行应该是/differnt/path/to/B.h
因为指针跳过/path/to/B.h
并位于/path/to/A.h
. 当它需要读取B.h
时,从 开始/path/to/A.h
,没有找到它,然后转到-I
包含的下一条路径,即/different/path/to/B.h
. 这是预处理的工作原理吗?如果没有,有人可以正确解释吗?
解决方案
推荐阅读
- http - 未创建对象的 Http 状态
- android - 如何将列表视图放入具有最大高度限制的约束布局中?
- android - 小米红米Note8 Pro及以上蓝牙“附加设置”
- python - 优化python代码蒙特卡罗模拟
- android - 部分订阅正在退款
- java - 如何将我的 java 代码包含到从 aapt2 链接生成的 apk 中?
- c++ - 高于 int 的 C++ 类型提升
- matlab - 如何使用 MATLAB 应用程序编译器将作者姓名添加到创建的 exe 文件中?
- python - Minikube 上的 Flask 应用程序使用入口拒绝连接
- docker - 为什么我在运行 docker-compose 时无法通过其名称访问另一个 docker 容器