LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   can anyone explain kernel headers? (https://www.linuxquestions.org/questions/linux-newbie-8/can-anyone-explain-kernel-headers-210546/)

class_struggle 07-28-2004 06:03 AM

can anyone explain kernel headers?
 
Hi,

Setting up my winmodem for a second time has led me to the kernel header files once more.

The fact is, I don't know what they are. Are they a special sort of module that can be read in by the kernel? why are they spearated from the kernel. What does the kernel do with them?

RobertP 07-28-2004 07:22 AM

Drivers are a part of the Linux kernel, but they may be developed separately at different times and places. If you write a driver and wish it to work with Linux x.y, you do not need to have Linux x.y handy, just the kernel headers, which contain all the information needed by compilers to make the driver files. The headers essentially tell the world how to pass information to the kernel and how to receive information from the kernel. When you install any software that needs this intimate knowledge of the kernel, the kernel header files will be required to be present. When a programme or driver is loaded or linked, any references to the kernel can be satisfied by the loader/linker. This process is similar to using a precompiled library with any programming language. The source files refer to external symbols which may be used by the compiler to generate linkages to libraries and other external objects.

The second computer job in my career was working with a primitive operating system. The applications were always loaded to the same absolute location in memory. A list of symbols that were addresses of locations in the operating system were available at the time of compiling the application. The result was that we could get a separately compiled application to behave as if it were compiled along with the operating system as one big programme. It was very crude, but it worked, sometimes ...;) The kernel headers are a similar concept brought up to date.

class_struggle 07-28-2004 08:07 AM

That was a cool reply, thanks RobertP!

Inevitably I have 2 further questions (but then I'll stop, all right?:-))

1. Are headers then generated from the kernel in use? That would make them consistent with that kernel's configuration. I can remember last time though, I simply downloaded them, so they couldn't have reflected the kernel's exact config.

2. In an otherwise very clear explanation, I was sure what you meant by
Quote:

The source files refer to external symbols which may be used by the compiler to generate linkages to libraries and other external objects.
Do you mean the driver source file or the kernel sources? By external symbols, are you including the kernel calls (for lack of a better word)?

RobertP 07-28-2004 08:27 AM

The folks who write/maintain the kernel, produce matching headers for each kernel.

The source file of an application/driver will refer to a symbol defined in the kernel header files. The source file will usually have something that says "include the kernel headers with this source". The compiler will then treat the headers as a part of the source it is compiling and the definitions in the headers will produce the right linkages in the output of the compiler.

An example: If a programme needs to know what an error code means, it can refer to errno.h in kernel-headers

errno.h contains stuff like this:
errno.h

External symbols can be constants, routine locations, data locations, configuratioin settings


All times are GMT -5. The time now is 02:18 PM.