LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Linux kernel header files (https://www.linuxquestions.org/questions/programming-9/linux-kernel-header-files-296956/)

cranium2004 03-02-2005 08:45 PM

Linux kernel header files
 
Hello,
Why linux kernel header files start with defining constant variables? EX. header file list.h
#ifndef _LINUX_LIST_H
#define _LINUX_LIST_H
also header file lock.h
#ifndef _LINUX_LOCKS_H
#define _LINUX_LOCKS_H
Why they are defined and where its require by kernel?

jtshaw 03-02-2005 08:57 PM

They are defined that way so if you have two different source files that end up in the same binary you won't have symbols defined twice. If you remove those you'll notice a lot of multiple definition errors when you compile things.... especially the kernel:)

If you are building a large project with header files that are included in lots of different source files it is common practice to do things that way to ensure you don't have multiple definitions of the same variables and functions. Even if all the definitions are the same, it will cause massive linker errors.

95se 03-02-2005 09:53 PM

Even with those, you'll still get crap loads of multiple definition errors though :( I'm writing an app for my wireless card write now and I had to play around with the order of the include files for 30 minutes just to get it to compile :eek:

jtshaw 03-02-2005 10:25 PM

Really? I'm curious as to what includes your having problems with. I do a lot of kernel development and device driver development and never run into those problems.

cranium2004 03-04-2005 04:41 AM

Thanks for reply. I got it. But one thing i also want to know if list.h and my1.h is included by my1.c where suppose my1.h already included list.h then if in file i add header file in sequence like
#include <lish.h>
#include "my1.h"
then how the definition _LINUX_LIST_H can be resolved? Does kernel stores all these defined variable in any files to resolve same files not to be added avoiding multiple definitions?


All times are GMT -5. The time now is 02:01 AM.