LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices

Reply
 
LinkBack Search this Thread
Old 02-01-2012, 11:11 PM   #1
chandramohan N
LQ Newbie
 
Registered: Feb 2012
Posts: 2

Rep: Reputation: Disabled
gcc giving error linux/init.h: No such file or directory


hey m new to the kernel programming, am trying to build a simple hello world kernel module. when i executed the make file its working well even i can insert and remove module in kernel modules. but when i try to compile module with gcc its giving errors.

am using boss os and kernel version is 3.0, latest gcc is also installed in my system.

my hello world program is:

vim hello.c
#include<linux/init.h>
#include<linux/module.h>
#include<linux/kernel.h>

static int start_mod()
{
printk("initialize kernel module\n");
printk("hello world!\n");
return 0;
}
static void end_mod()
{
printk("kernel module unloaded.\n");
}

module_init(start_mod);
module_exit(end_mod);

and
my make file is:

vim Makefile
obj-m+=hello.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
 
Old 02-02-2012, 12:32 AM   #2
lisle2011
Member
 
Registered: Mar 2011
Location: Surrey B.C. Canada (Metro Vancouver)
Distribution: Slackware 2.6.33.4-smp
Posts: 179
Blog Entries: 1

Rep: Reputation: 24
Kernel programming

Since you received gcc error giving up that info would have been good.

However, lots of folks do this and this link will tell you exactly what you need to do. Whether or not it is advisable I cannot say, kernel hacking is not a forte of mine, but the folks at this link do it all the time. You could do well to have a good read. Their code for something similar is different than yours, since the outcome will be the same you should probably go with these kernel hackers.

First, bring up the file init/main.c in your favorite editor
Find the calibrate_delay(void) function in the file.

The first lines are declarations of a few variables, and will look something like this:

unsigned long ticks, loopbit;
int lps_precision = LPS_PREC;

Now, type in the following line just below them:

printk("*** I am a kernel hacker! ***\n");

Just a taster for you, read the whole page. If you want Kernel Hacking this place works.

http://www.linuxchix.org/content/cou...acking/lesson5

Bon chance

------------------------------------------------------------------------------------------------------------
Give me pat on the back if it works for you
 
1 members found this post helpful.
Old 02-02-2012, 03:25 AM   #3
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2010.12, Slack1337 DebSqueeze, +50+ other Linux OS, for test only.
Posts: 9,287

Rep: Reputation: 1350Reputation: 1350Reputation: 1350Reputation: 1350Reputation: 1350Reputation: 1350Reputation: 1350Reputation: 1350Reputation: 1350Reputation: 1350
Quote:
make -C /lib/modules/$(shell uname -r)/build .........
The link build must point to a location like
/usr/src/linux/ or /usr/src/3.0/ ,
to find e.g. /usr/src/3.0/include/linux/init.h


Your code compiles OK with the standard Makefile :
Code:
obj-m    := hello.o

KDIR    := /lib/modules/$(shell uname -r)/build
PWD    := $(shell pwd)

default:
	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

Last edited by knudfl; 02-02-2012 at 03:39 AM.
 
Old 02-05-2012, 10:29 PM   #4
chandramohan N
LQ Newbie
 
Registered: Feb 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Am using debian os ,kernel version 3.0 and its latest gcc and headers are also installed in my computer.
when i try to compile my simple kernel module hello world program using gcc its giving error.

hello.c:1:23: error: linux/init.h: No such file or directory
hello.c:2:25: error: linux/module.h: No such file or directory
hello.c:16: warning: data definition has no type or storage class
hello.c:16: warning: parameter names (without types) in function declaration
hello.c:17: warning: data definition has no type or storage class
hello.c:17: warning: parameter names (without types) in function declaration

my hello world program is
#include<linux/init.h>
#include<linux/module.h>
#include<linux/kernel.h>

static int start_mod()
{
printk("initialize kernel module\n");
printk("hello world!\n");
return 0;
}
static void end_mod()
{
printk("kernel module unloaded.\n");
}

module_init(start_mod);
module_exit(end_mod);

and my Makefile is
obj-m+=hello.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
 
Old 02-06-2012, 02:44 AM   #5
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2010.12, Slack1337 DebSqueeze, +50+ other Linux OS, for test only.
Posts: 9,287

Rep: Reputation: 1350Reputation: 1350Reputation: 1350Reputation: 1350Reputation: 1350Reputation: 1350Reputation: 1350Reputation: 1350Reputation: 1350Reputation: 1350
Please edit posts #1 and #4 to use CODE tags :
Write [/code] at code end, and [code] at code text start.
Or use the # button in the 'Advanced Editor'.
http://www.linuxquestions.org/questi....php?do=bbcode

Your Makefile works OK
Code:
obj-m+=hello.o

all:
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
... So I guess your link /lib/modules/`uname -r`/build
is not pointing to /usr/src/linux-3.0/

.
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
gcc: error trying to exec 'as': execvp: No such file or directory vanish78 Linux - Software 4 10-12-2011 02:15 AM
[SOLVED] GCC Pass 1 ERROR ( mpc.h: No such file or directory ) dgashu Linux From Scratch 3 09-18-2011 12:54 PM
I am getting an error as gcc: c-parse.c: No such file or directory pradheep2 Linux - General 5 06-12-2010 05:13 AM
init: Error parsing configuration: no such file or directory ternarybit Linux - Software 1 03-21-2010 05:00 PM
gcc error: iostream: no such file or directory linux 4.1.2 Liah Linux - Newbie 1 03-10-2009 10:53 AM


All times are GMT -5. The time now is 10:43 PM.

Main Menu
 
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
Open Source Consulting | Domain Registration