How can I find the header files of the C programming language in Linux?

前端 未结 10 1763
南笙
南笙 2020-12-07 08:42

When I write C programs in Linux, and then compile them using gcc, I am always curious about where those header files are. For example, where stdio.h is. More g

相关标签:
10条回答
  • 2020-12-07 09:18

    If you use gcc, you can check a specific file with something like:

    echo '#include <stdbool.h>' | cpp -H -o /dev/null 2>&1 | head -n1
    

    -H asks the preprocessor to print all included files recursively. head -n1 takes just the first line of output from that, to ignore any files included by the named header (though stdbool.h in particular probably doesn't).

    On my computer, for example, the above outputs:

    . /usr/lib/gcc/x86_64-linux-gnu/4.6/include/stdbool.h
    
    0 讨论(0)
  • 2020-12-07 09:18

    During the preprocessing all preprocessor directives will be replaced with the actuals. Like macro expansion, code comment removal, including the header file source code etc...

    we can check it by using the 'CPP' - C PreProcessor command.

    For example in the command line,

    cpp Filename.c

    It will display the preprocessed output.

    0 讨论(0)
  • 2020-12-07 09:23

    One approach, if you know the name of the include file, would be to use find:

    cd /
    find . -name "stdio.h"
    find . -name "std*.h"
    

    That'll take a while as it goes through every directory.

    0 讨论(0)
  • 2020-12-07 09:23

    Most standard headers are stored in /usr/include. It looks like stdbool.h is stored somewhere else, and depends on which compiler you are using. For example, g++ stores it in /usr/include/c++/4.7.2/tr1/stdbool.h whereas clang stores it at /usr/lib/clang/3.1/include/stdbool.h.

    0 讨论(0)
提交回复
热议问题