Reputation: 40878
When I compile with gcc -v hello.c
*, the output shows a search path for #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>
. I can see manually that there are versions of stdio.h
in multiple locations, presumably which can use different function construction:
$ 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:
>>> 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.
Upvotes: 5
Views: 344
Reputation: 31306
From gcc man page:
-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. 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 ...! .
Upvotes: 6