代码之家  ›  专栏  ›  技术社区  ›  Brad Solomon

确定头文件的位置

  •  5
  • Brad Solomon  · 技术社区  · 8 年前

    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.
    

    有没有办法确定使用这些位置中的哪一个? 比如说 hello.c #include <stdio.h> . 我可以手动看到 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
    

    在Python中,这看起来像:

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

    *我在用Macbook,所以 gcc 实际上似乎是 clang ,尽管它看起来是一个真正的可执行文件,而不是符号链接。

    1 回复  |  直到 8 年前
        1
  •  6
  •   klutt    8 年前

    gcc man 页码:

    -小时

    打印使用的每个头文件的名称,以及其他正常活动的名称。每个名称都缩进以显示包含堆栈的深度。即使发现预编译头文件无效,也会打印它们;无效的预编译头文件用…x打印,有效的用。