On linux, there is socket.h under many folders as shown below.
How is it decided as to what is stored under asm folder vs linux vs bits. I am assuming everything under sys is simply libc
In what order do the header files get resolved by gcc. Does it for example pick socket.h from sys, then linux, then sys, then bits so on?
/usr/include/sys/socket.h, (used by libc)
/usr/include/linux/socket.h
/usr/include/asm/socket.h
/usr/include/asm-generic/socket.h
/usr/include/bits/socket.h (included by libc)
1) A bare #include <socket.h> won't work in default linux configurations:
fatal error: socket.h: No such file or directory
This means that you have to specify the subdirectory of a directory in the gcc search path also: #include <sys/socket.h> (relative to /usr/include, so the absolute path is /usr/include/sys/socket.h). To determine what header file to use, look at man socket.
In general /usr/include/sys contains end-user headers, whereas bits/asm contain intermediate headers, used by gcc and other headers. /usr/include/linux contains Linux-specific headers (often shared with the kernel, so it's description of kernel structures that may be useful for userspace programming).
Libc headers are generally scattered throughout the whole /usr/include. Gcc-specific headers are often in places like /usr/include/x86_64-linux-gnu and such.
2)
Here: http://gcc.gnu.org/onlinedocs/cpp/Search-Path.html you can find more information about the GCC search paths. None of the guessed directories are searched, just /usr/include and others on the list in the link.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With