简体   繁体   English

确定找到头文件的位置

[英]Determining where header file is found

When I compile with gcc -v hello.c * , the output shows a search path for #include : 当我用gcc -v hello.c *编译时,输出显示#include的搜索路径:

$ gcc -v hello.c
Apple LLVM version 9.1.0 (clang-902.0.39.2)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
...
clang -cc1 version 9.1.0 (clang-902.0.39.2) default target x86_64-apple-darwin17.7.0
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /Library/Developer/CommandLineTools/usr/lib/clang/9.1.0/include
 /Library/Developer/CommandLineTools/usr/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.

Is there a way to determine definitively which of these locations is used? 有没有办法确定使用哪些位置? For example, say that hello.c contained #include <stdio.h> . 例如,假设hello.c包含#include <stdio.h> I can see manually that there are versions of stdio.h in multiple locations, presumably which can use different function construction: 我可以手动看到有多个位置的stdio.h版本,大概可以使用不同的函数构造:

$ find /usr/local/include -name "stdio.h"
/usr/local/include/c++/5.5.0/tr1/stdio.h

$ find /Library/Developer/CommandLineTools/usr/include -name "stdio.h"
/Library/Developer/CommandLineTools/usr/include/c++/v1/stdio.h

$ find /usr/include -name "stdio.h"
/usr/include/c++/4.2.1/tr1/stdio.h
/usr/include/sys/stdio.h
/usr/include/stdio.h

In Python, this would look something like: 在Python中,这看起来像:

>>> import math
>>> math.__file__
'/Users/brad/miniconda3/lib/python3.6/lib-dynload/math.cpython-36m-darwin.so'

*I'm on a Macbook, so gcc actually seems to route to clang , although it appears to be a bona fide executable rather than symlink. *我使用的是Macbook,所以gcc实际上似乎是要传递给clang ,尽管它似乎是一个真正的可执行文件而不是符号链接。

From gcc man page: 来自gcc手册页:

-H -H

Print the name of each header file used, in addition to other normal activities. 除了其他正常活动之外,还打印所使用的每个头文件的名称。 Each name is indented to show how deep in the #include stack it is. 每个名称都缩进以显示#include堆栈的深度。 Precompiled header files are also printed, even if they are found to be invalid; 即使发现它们无效,也会打印预编译的头文件; an invalid precompiled header file is printed with ...x and a valid one with ...! 一个无效的预编译头文件打印有... x和一个有效的... .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM