Welcome to Linux Forums!

With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.

Linux Forum ArticlesLinux ForumsLinux Forum DownloadsLinux HostsFree MagazinesJobs
Home|Register|FAQ|Member List|Calendar|Unanswered Posts|Forum Rules|Today's Posts|Advanced Search|
SEARCH FOR IN
Go Back   Linux Forums > GNU Linux Zone > The Linux Kernel
Reload this Page Kernel module not compiling
Linux Forums
Linux Forums
Welcome To The Linux Forums!
Welcome to Linux Forums. We pride ourselves in being one of the largest Linux communities on the web, we encourage you to REGISTER on our forums and participate in the community. There are over 150,000 members ready to answer your questions. JOINING US today will allow you to make new posts, get support, send messages to other members and submit downloads to our downloads directory and many other great features!

The Linux Kernel Compiling, theory, programming or other discussion about the linux kernel

Reply
 
Thread Tools Display Modes
Old 01-05-2008   #1 (permalink)
Just Joined!
 
kdev981's Avatar
 
Join Date: Dec 2007
Location: Hyderabad,(A.P.) India.
Posts: 14
Angry Kernel module not compiling

My very first attempt to compile a simple kernel module has gone waste,

This is the code for the module:
Code:
//Our first kernel program!!
#include <linux/module.h>
#include <linux/kernel.h>

int init_module(void)
{
 printk("<1> Hello Kernel world!!");
 return 0;
}

void cleanup_module(void)
{
 printk(KERN_ALERT "Goodbye Kernel world!");
}
and the makefile

Code:
TARGET  := hello-1
WARN    := -W -Wall -Wstrict-prototypes -Wmissing-prototypes
INCLUDE := -isystem /lib/modules/`uname -r`/build/include
CFLAGS  := -O2 -DMODULE -D__KERNEL__ ${WARN} ${INCLUDE}
CC      := gcc

${TARGET}.o: ${TARGET}.c

.PHONY: clean

clean:
        rm -rf ${TARGET}.o
This is taken from the free ebook Linux Kernel Module programming.

and here's the output:

Code:
[root@localhost hello-1]# make
gcc -O2 -DMODULE -D__KERNEL__ -W -Wall -Wstrict-prototypes -Wmissing-prototypes -isystem /lib/modules/`uname -r`/build/include   -c -o hello-1.o hello-1.c
In file included from /lib/modules/2.6.23.1-42.fc8/build/include/linux/prefetch.h:14,
                 from /lib/modules/2.6.23.1-42.fc8/build/include/linux/list.h:8,
                 from /lib/modules/2.6.23.1-42.fc8/build/include/linux/module.h:9,
                 from hello-1.c:2:
/lib/modules/2.6.23.1-42.fc8/build/include/asm/processor.h:83: error: ‘CONFIG_X86_L1_CACHE_SHIFT’ undeclared here (not in a function)
/lib/modules/2.6.23.1-42.fc8/build/include/asm/processor.h:83: error: requested alignment is not a constant
In file included from /lib/modules/2.6.23.1-42.fc8/build/include/linux/module.h:20,
                 from hello-1.c:2:
/lib/modules/2.6.23.1-42.fc8/build/include/asm/module.h:69:2: error: #error unknown processor family
make: *** [hello-1.o] Error 1
I wonder how the processor family is unknown, since the same kernel is running on this machine (2.6.23.1-42.fc8 )

Please help!
kdev981 is offline   Reply With Quote
Old 01-05-2008   #2 (permalink)
Linux Enthusiast
 
Franklin52's Avatar
 
Join Date: Aug 2006
Posts: 596
Try this makefile, place one real tab before a make statement (not spaces!):

Code:
obj−m += hello−1.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

Regards
Franklin52 is offline   Reply With Quote
Old 01-21-2008   #3 (permalink)
Just Joined!
 
Join Date: Jan 2008
Posts: 1
Try this:

Delete everything inyour Makefile, and add this:

obj-m += hello-1.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
judepereira is offline   Reply With Quote
Old 01-24-2008   #4 (permalink)
Just Joined!
 
Join Date: Jan 2008
Posts: 3
Hi
Even i am working on my first hello world program in modifying the kernel. I have just began to get familiarized with linux, so i dont have a lot of practice with the makefiles.
This is my kernel program

#define MODULE
#include <linux/module.h>

int init_module(void)
{
printk("hello\n");
return 0;
}

void cleanup_module(void)
{
printk("bbye\n");
}

I have been trying to search for the makefile to use for this.
If i run the program using the gcc command (as stated in the book - O Reilly)

#gcc -c hello.c

usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../crt1.o(.text+0x1: In function `_start':
../sysdeps/i386/elf/start.S:77: undefined reference to `main'
/tmp/cc6tY8ap.o(.text+0xf): In function `init_module':
: undefined reference to `printk'
/tmp/cc6tY8ap.o(.text+0x2c): In function `cleanup_module':
: undefined reference to `printk'
collect2: ld returned 1 exit status

the linux i am using presently is 2.4.20-8
I have tried to search about this error and similar pots online, but couldnt find anything. Could someone please help me with this? Or if similar question has been asked before to post the link so that i can get my program working

thanks in advance

gagan
phro is offline   Reply With Quote
Old 01-25-2008   #5 (permalink)
Just Joined!
 
Join Date: Jun 2006
Posts: 25
include these headers

#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>



and compile with
gcc -c -O2 -Wall -isystem /lib/modules/`uname -r`/build/include -D__KERNEL__ -DMODULE xxxx.c

spend some time on understanding that copile command it helps you a lot.

keep coding ...
ashok449 is offline   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
i have trouble with my web-server which have been built on Centos5 lashalejava Redhat / Fedora Linux Help 18 12-14-2007 03:44 PM
USB HD (enclosure) changing mountpoins Everytime I copy files . . . icedtea Peripherals / Hardware 0 10-11-2007 02:14 PM
External USB Hard Drive a1m2x5 Linux Newbie 0 07-06-2007 08:00 PM
Where to find the errors when machine hangs up? walking The Linux Kernel 12 07-16-2005 08:07 PM
Mouse is crazy after X window starts. fli3818 Linux Desktop / X-Windows 2 04-02-2004 05:09 PM

Free Magazines
Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe
Systems Management News, the newspaper for IT systems administration and data center managers!
Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe
The Enterprise Newsweekly
eWeek is the essential technology information source for builders of e-business.
subscribe
Oracle Magazine
Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe
Total Telecom
Total Telecom is "The Economist of the communications industry".
subscribe
More free magazines »



All times are GMT. The time now is 06:54 AM.




© 2000 - 2008 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.2.0