LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 03-02-2005, 09:45 PM   #1
cranium2004
Member
 
Registered: Feb 2004
Distribution: FC4,RHEL4
Posts: 223

Rep: Reputation: 30
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?
 
Old 03-02-2005, 09:57 PM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
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.

Last edited by jtshaw; 03-02-2005 at 09:59 PM.
 
Old 03-02-2005, 10:53 PM   #3
95se
Member
 
Registered: Apr 2002
Location: Windsor, ON, CA
Distribution: Ubuntu
Posts: 740

Rep: Reputation: 32
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
 
Old 03-02-2005, 11:25 PM   #4
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
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.
 
Old 03-04-2005, 05:41 AM   #5
cranium2004
Member
 
Registered: Feb 2004
Distribution: FC4,RHEL4
Posts: 223

Original Poster
Rep: Reputation: 30
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?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What!? Kernel header files too old? LinuxLuvr Linux From Scratch 2 06-20-2005 09:43 AM
Kernel Header Files apocolpse Suse/Novell 3 11-19-2004 01:48 PM
c header files in linux in place of header files in windows? harun_acs Programming 1 03-17-2004 03:24 AM
Kernel Header Files? kholdstayr Slackware 1 12-22-2003 05:45 PM
where are the kernel header files? vance Linux - Software 5 03-05-2002 02:51 AM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration