How to tell where a header file is included from?(如何判断头文件是从哪里包含的?)
问题描述
我如何知道 g++ 在哪里能够找到包含文件?基本上如果我
How can I tell where g++ was able to find an include file? Basically if I
#include <foo.h>
g++ 将扫描搜索路径,使用任何包含选项来添加或更改路径.但是,归根结底,有没有办法告诉我 g++ 选择编译的 foo.h 的绝对路径?如果在无数搜索路径中存在多个 foo.h,则尤其相关.
g++ will scan the search path, using any include options to add or alter the path. But, at the end of days, is there a way I can tell the absolute path of foo.h that g++ chose to compile? Especially relevant if there is more than one foo.h in the myriad of search paths.
缺少一种实现方式...有没有办法让 g++ 告诉我在包含默认值和所有包含选项后它的最终搜索路径是什么?
Short of a way of accomplishing that... is there a way to get g++ to tell me what its final search path is after including defaults and all include options?
推荐答案
这将给出列出包含文件绝对路径的 make 依赖项:
This will give make dependencies which list absolute paths of include files:
gcc -M showtime.c
如果您不希望系统包含(即#include
),请使用:
If you don't want the system includes (i.e. #include <something.h>
) then use:
gcc -MM showtime.c
这篇关于如何判断头文件是从哪里包含的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何判断头文件是从哪里包含的?


基础教程推荐
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 常量变量在标题中不起作用 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07