#Include statements containing a slash (two-part header files)

Sometimes I see form header files.

#include <sys/sysinfo.h> // I found this on my system under /usr/include/sys/sysinfo.h. Is that all the "sys/" means? 

What is it called and why are these header files different from most others, such as

 #include <stdio.h> 

Perhaps a group of related header files was grouped under the label "sys", but if I try something like "man pci" (there is no header pci.h in / usr / include / sys /.

+7
c
source share
3 answers

This is a convenient way to provide some “namespace structure” in header files. In the Unix world, the main separation is between headers of type <stdio.h> , which are often quite common and primarily for use by user programs, and not for the kernel of the operating system. In contrast, headers like <sys/sysinfo.h> or <sys/types.h> intended to be used to compile the kernel — they were more systemic. Y.

Currently, it provides the ability to separate project titles from other project titles. For example, <openssl/ssl.h> identifies the header as belonging to the OpenSSL code base.

I do not know that there is a specific name for this header designation style.

Note that if the OpenSSL headers are stored in the /usr/local/include/openssl directory, then you specify -I /usr/local/include on the compiler command line. What actually happens is that the title is viewed by prefixing the name in angle brackets with one of several standard directories, of which /usr/include is used by default on Unix. Therefore, <stdio.h> is in /usr/include/stdio.h , and <sys/sysinfo.h> is in /usr/include/sys/sysinfo.h , etc.

+8
source share

They are still headers, but they are not directly in the default search path. This is often done for third-party library headers so that they do not separate from the libc headers.

+2
source share

This is due to how your preprocessor works. If your preprocessor looks in /usr/include/ , you need sys/sysinfo.h . If your preprocessor looks in /usr/include/sys/ , you only need sysinfo.h

Try playing with gcc with the -I and -l options

edit: those should be capital i and lowercase letters L

+2
source share

All Articles