How can I tell where g++ was able to find an include file? Basically if I
我如何知道g++在哪里可以找到包含文件?基本上如果我
#include <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++将扫描搜索路径,使用任何包含选项来添加或改变路径。但是,最后,有没有一种方法可以告诉我foo的绝对路径。h g++选择编译?特别是当有多个foo时。h在无数的搜索路径中。
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?
缺少实现这一点的方法……有没有办法让g++在包含默认值和所有包含选项之后告诉我它的最终搜索路径?
4 个解决方案
#1
53
This will give make dependencies which list absolute paths of include files:
这将使依赖项列出包含文件的绝对路径:
gcc -M showtime.c
If you don't want the system includes (i.e. #include <something.h>
) then use:
如果您不希望系统包含(例如:#include
gcc -MM showtime.c
#2
65
g++ -H ...
will also print the full path of include files in a format which shows which header includes which
还将打印包含文件的完整路径,以显示哪些头包含哪些头
#3
4
Sure use
确定使用
g++ -E -dI ... (whatever the original command arguments were)
#4
3
If you use -MM
or one of the related options (-M
, etc), you get just the list of headers that are included without having all the other preprocessor output (which you seem to get with the suggested g++ -E -dI
solution).
如果您使用-MM或其中一个相关选项(-M,等等),您只会得到包含在其中的头信息列表,而不会得到所有其他预处理器输出(您似乎可以通过建议的g++ -E -dI解决方案获得这些信息)。
#1
53
This will give make dependencies which list absolute paths of include files:
这将使依赖项列出包含文件的绝对路径:
gcc -M showtime.c
If you don't want the system includes (i.e. #include <something.h>
) then use:
如果您不希望系统包含(例如:#include
gcc -MM showtime.c
#2
65
g++ -H ...
will also print the full path of include files in a format which shows which header includes which
还将打印包含文件的完整路径,以显示哪些头包含哪些头
#3
4
Sure use
确定使用
g++ -E -dI ... (whatever the original command arguments were)
#4
3
If you use -MM
or one of the related options (-M
, etc), you get just the list of headers that are included without having all the other preprocessor output (which you seem to get with the suggested g++ -E -dI
solution).
如果您使用-MM或其中一个相关选项(-M,等等),您只会得到包含在其中的头信息列表,而不会得到所有其他预处理器输出(您似乎可以通过建议的g++ -E -dI解决方案获得这些信息)。