3 Answers
3

Hi 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.
For this task the actual implementation of the function is not necessary.

You could do the same with the complete kernel sources but you will install a lot of unnecessary files.

Example:

if I want to use the function

int foo(double param);

in a program I do not need to know how the implementation of foo is, I just need to know that it accepts a single param (double) and returns an integer.

As stated, header files define interfaces to functions as well as structures used by programs.

In the case of the kernel header files, these functions and structures are within the kernel itself.

If you are building a complete kernel, then, obviously, you need the complete source files, not just the headers. However, if you are compiling a device driver or other loadable module which links into the kernel then you only need the header files, so can save space by not installing the full sources.

The separation of packages so that you can install just the header files is partly historical as the difference in disk usage used to be a significant consideration when disks were smaller. These days, having the entire source on disk (unnecessarily) would not be a major disk space consideration.

The term header files originates from the C programming language used in writing the Linux kernel.

To explain it from a very high level...

Un C you need to have a forward declaration of a function before using it. In other words, a description of the function, its parameters, and what kind of data it returns. It's common practice to put all of the forward declarations into a single file called a header. Source code files for other programs can then an include statement for this header and have access to all of the functions in the resulting program executable once it has been compiled.

The Linux header files are all of the .h files that contain the functions that the Linux kernel provides that can be called from other programs.