Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 09-08-2007, 11:11 PM   #1
LQ Newbie
Registered: Sep 2007
Posts: 1

Rep: Reputation: 0
help me ..inserting a modle

hi All

i was trying to insert a module ..but it is giving compilation error ..

[root@localhost test]# gcc -D__KERNEL__ -I/usr/src/linux/include -O -Wall -c hello1.c
In file included from /usr/src/linux/include/asm/thread_info.h:16,
from /usr/src/linux/include/linux/thread_info.h:21,
from /usr/src/linux/include/linux/preempt.h:9,
from /usr/src/linux/include/linux/spinlock.h:49,
from /usr/src/linux/include/linux/module.h:9,
from hello1.c:1:
/usr/src/linux/include/asm/processor.h:83: error: `CONFIG_X86_L1_CACHE_SHIFT' undeclared here (not in a function)
/usr/src/linux/include/asm/processor.h:83: error: requested alignment is not a constant
In file included from /usr/src/linux/include/linux/module.h:21,
from hello1.c:1:
/usr/src/linux/include/asm/module.h:64:2: #error unknown processor family

i am using linux- from ..

please help me out guys ... this is my first linux kernel level program
Old 09-09-2007, 09:50 AM   #2
Registered: Mar 2004
Location: Canada
Distribution: Slackware current
Posts: 728
Blog Entries: 2

Rep: Reputation: 43
It would seem to me you need to #include /usr/src/linux/.config so that CONFIG_X86_L1_CACHE_SHIFT is defined properly. Naturally this assumes you've configured first.

As a general rule you don't want to compile as root, and especially not in /usr/src/linux - you ought to copy the source to some other location (like ~/src/linux) and build there, only installing as root.
Old 09-09-2007, 01:21 PM   #3
HCL Maintainer
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 77
It seems like you are using an older (2.4) method on newer (2.6) kernels. Moreover, you are including your header files from /usr/src/linux instead of those matching to your particular kernel (this may point to your actual kernel sources, but this is not the recommended way).

First off, please don’t do this:
Originally Posted by ciotog View Post
It would seem to me you need to #include /usr/src/linux/.config so that CONFIG_X86_L1_CACHE_SHIFT is defined properly.
Basically, on newer kernels, everyone is advised to use the kernel make system. This means you will change directory to your kernel build tree, run “make” from there with some magical options which make the make system compile and link your module. If you just want to use this without all the explanation, skip down to the Makefile at the end.

First, we need the kernel build tree: If you compiled your kernel from source and installed modules with “make modules_install” (on your 2.6 kernel), it should have created a directory “/lib/modules/`uname -r`” which has a two symlinks: “source” points to the kernel source tree, and “build” points to the kernel build tree (note, that in most cases, they are the same).

The build tree is needed intact for this to work. Next, we need to know some of the magical variables we pass to the make system. The first such option tells the make system you want to compile external module(s) which reside in the directory you specify. This is “M” variable (alternatively, you could use the older “SUBDIRS” variable).

The other variable will tell the make system what to compile (in this case, your one file: hello1.c) and how to link it (in this case, as a module). To specify linkage as a module, you use the variable “obj-m” (the value of this variable is the same name as the source file except the suffix is “.o” rather than “.c”).

Now, we should be set for making your module. Basically, this is what you do (replace “/path/to/your/source” with the location of “hello1.c”):
$ make -C /lib/modules/`uname -r`/build M=/path/to/your/source obj-m=hello1.o
You should end up with (among other new files) a file named “hello1.ko” in the directory you specified. This is your module which you can insert with “insmod hello1.ko” (as root). Alternatively, you can install the module like this:
# make -C /lib/modules/`uname -r`/build M=/path/to/your/source obj-m=hello1.o modules_install
and insert it with “modprobe hello1” (as root).

If you don’t want to do this by hand each time, you can create a Makefile that looks something like this:
	KERNELDIR  := /lib/modules/$(shell uname -r)/build

obj-m := hello1.o


	$(MAKE) -C $(KERNELDIR) M=$(PWD) clean

	$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
	/sbin/depmod -ae
Place this file in the same directory that contains hello1.c, and just run “make” to build your module.


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
Inserting Manpages bhandu Linux - Software 2 03-20-2006 11:25 AM
inserting nvidia? lilili Slackware 32 01-15-2006 07:12 AM
Setting up linuxbox as a router for windowsbox (my modle on the inside) Lechium Linux - Newbie 8 06-20-2004 05:25 AM
Inserting Text wildcat22 Linux - General 8 04-25-2004 08:51 AM
Inserting modules wgodois Linux - Hardware 0 08-03-2003 10:37 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:37 AM.

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