Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does gcc look for C and C++ header files?

Tags:

c

gcc

header

On a Unix system, where does gcc look for header files?

I spent a little time this morning looking for some system header files, so I thought this would be good information to have here.

like image 896
Bill the Lizard Avatar asked Oct 16 '22 13:10

Bill the Lizard


People also ask

Where does GCC look for header files?

GCC looks for headers requested with #include " file " first in the directory containing the current file, then in the directories as specified by -iquote options, then in the same places it would have looked for a header requested with angle brackets.

Does GCC need header files?

The declaration is used to ensure that the types of the arguments and return value match up correctly between the function call and the function definition. We no longer need to include the system header file 'stdio. h' in 'main.

Which option in GCC is used to specify the location of the .h files?

gcc -I adds include directory of header files.

Where are C header files stored in Linux?

The C library's header files include the kernel header files from the "linux" subdirectory. The system's libc headers are usually installed at the default location /usr/include and the kernel headers in subdirectories under that (most notably /usr/include/linux and /usr/include/asm).


1 Answers

`gcc -print-prog-name=cc1plus` -v

This command asks gcc which C++ preprocessor it is using, and then asks that preprocessor where it looks for includes.

You will get a reliable answer for your specific setup.

Likewise, for the C preprocessor:

`gcc -print-prog-name=cpp` -v
like image 246
Drew Dormann Avatar answered Oct 18 '22 01:10

Drew Dormann