Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 generally, where is stdbool.h?

What I want to know is not only where it is, but also how to get those places, for example, using shell command or using the C programming language.

like image 494
Yishu Fang Avatar asked Oct 26 '12 01:10

Yishu Fang


People also ask

Where are C header files located?

These are the directories that gcc looks in by default for the specified header files ( given that the header files are included in chevrons <>); 1. /usr/local/include/ --used for 3rd party header files. 2. /usr/include/ -- used for system header files.

HOW include header file in C linux?

To import a header, use the #include, a preprocessor directive telling the compiler that it should import and process the code before compiling the rest of the code. On a typical C program, it should contain the stdio. h header file, which is the standard header file for input and output streams.

What is header file in linux?

The header files define an interface: they specify how the functions in the source file are defined. They are used so that a compiler can check if the usage of a function is correct as the function signature (return value and parameters) is present in the header file.

What is the header file for files in C?

A header file is a file with extension . h which contains C function declarations and macro definitions to be shared between several source files. There are two types of header files: the files that the programmer writes and the files that comes with your compiler.


1 Answers

gcc -H ... will print the full path of every include file as a side-effect of regular compilation. Use -fsyntax-only in addition to get it not to create any output (it will still tell you if your program has errors). Example (Linux, gcc-4.7):

$ cat > test.c #include <stdbool.h> #include <stdio.h> ^D $ gcc -H -fsyntax-only test.c . /usr/lib/gcc/x86_64-linux-gnu/4.7/include/stdbool.h . /usr/include/stdio.h .. /usr/include/features.h ... /usr/include/x86_64-linux-gnu/bits/predefs.h ... /usr/include/x86_64-linux-gnu/sys/cdefs.h .... /usr/include/x86_64-linux-gnu/bits/wordsize.h ... /usr/include/x86_64-linux-gnu/gnu/stubs.h .... /usr/include/x86_64-linux-gnu/bits/wordsize.h .... /usr/include/x86_64-linux-gnu/gnu/stubs-64.h .. /usr/lib/gcc/x86_64-linux-gnu/4.7/include/stddef.h .. /usr/include/x86_64-linux-gnu/bits/types.h ... /usr/include/x86_64-linux-gnu/bits/wordsize.h ... /usr/include/x86_64-linux-gnu/bits/typesizes.h .. /usr/include/libio.h ... /usr/include/_G_config.h .... /usr/lib/gcc/x86_64-linux-gnu/4.7/include/stddef.h .... /usr/include/wchar.h ... /usr/lib/gcc/x86_64-linux-gnu/4.7/include/stdarg.h .. /usr/include/x86_64-linux-gnu/bits/stdio_lim.h .. /usr/include/x86_64-linux-gnu/bits/sys_errlist.h 

The dots at the beginning of each line count how deeply nested the #include is.

like image 167
zwol Avatar answered Sep 19 '22 05:09

zwol