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
I think the generic path is:
/usr/lib/gcc/$(ls /usr/lib/gcc/)/$(gcc -v 2>&1 | tail -1 | awk '{print $3}')/include/stdbool.h
locate stdio.h
or
mlocate stdio.h
but locate
relies on a database, if you have never updated it
sudo updatedb
you can also enquire gcc
to know what are the default directories that are scanned by gcc
itself:
gcc -print-search-dirs
Use vim to open your source file and put the curses on stdio.h and in normal mode, command 'gf' will let vim open the stdio.h file for you.
'Ctr + g' will let vim display the absolute path of stdio.h
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.
When I was looking for (on Fedora 25) I used "whereis stdio.h" For me, It was in /usr/include/stdio.h, /usr/shar/man/man3/stdio,3.gx. But when you are looking for the file, use whereis or locate
Use gcc -v
and you can check the include path.
Usually, the include files are in /usr/include
or /usr/local/include
depending on the library installation.