Ubuntu Forums ubuntu.com - launchpad.net - ubuntu help  

Go Back   Ubuntu Forums > The Ubuntu Forum Community > Other Community Discussions > Development & Programming > Programming Talk
Register Reset Password Forum Help Forum Council Search Today's Posts Mark Forums Read

Programming Talk
This forum is for all programming questions.
The questions do not have to be directly related to Ubuntu and any programming language is allowed.

 
Thread Tools Display Modes
Old October 6th, 2007   #1
fr0ike
First Cup of Ubuntu
 
Join Date: Nov 2006
Beans: 2
[solved] errors compiling modules

hi,

i want to learn how to build device drivers (kernel modules). so i bought a book and started to read...
i`ve copied some piece of code from the book and tried to compile them,
but there are some errors popped up i can`t solve myself. i hope you can help me out...

*******************************
module source
*******************************

#define _LINUX_TIME_H 1 //thats to solve the "Redefinition von »struct timespec«" problem

#include <linux/version.h>
#include <linux/module.h>


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

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

MODULE_LICENSE("GPL");
*******************************

*******************************
Makefile (changed, perhaps its a piece of crap, i`m not very familiar with makefiles)
*******************************
obj-m := mod1.o
mod1.o: mod1.c
*******************************


*******************************
output
*******************************
$make
cc -c -o mod1.o mod1.c
In Datei, eingefügt von /usr/include/linux/sched.h:16,
von /usr/include/linux/module.h:9,
von mod1.c:4:
/usr/include/linux/signal.h:2:2: Warnung: #warning "You should include <signal.h>. This time I will do it for you."
In file included from mod1.c:4:
/usr/include/linux/module.h:41: Fehler: Feld »attr« hat unvollständigen Typen
/usr/include/linux/module.h:49: Fehler: Feld »kobj« hat unvollständigen Typen
make: *** [mod1.o] Fehler 1
*******************************

*******************************
Makefile from book
*******************************
ifneq ($(KERNELRELEASE),)
obj-m := mod1.o

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

default:
$(MAKE) -C $(KDIR) M=$(PWD) modules
endif
*******************************

*******************************
output
*******************************
$make
make: *** Keine Targets. Schluss.
*******************************


some info:

linux-headers-2.6.15-29-686
linux-source-2.6.15
ubuntu 6.06 "dapper drake"
gcc-Version 4.0.3 (Ubuntu 4.0.3-1ubuntu5)


Thanks in advance!
fr0ike

Last edited by fr0ike; October 6th, 2007 at 06:03 PM.. Reason: [solved]
fr0ike is offline   Reply With Quote
Old October 6th, 2007   #2
moma
Quad Shot of Ubuntu
 
moma's Avatar
 
Join Date: Jan 2006
Location: Grønland,Oslo
Beans: 484
Re: errors compiling modules

Hello,

Try this

File:mod1.c
Code:
/* 
#define _LINUX_TIME_H 1 
thats to solve the "Redefinition von »struct timespec«" problem
*/

#include <linux/version.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/moduleparam.h>

#include <linux/time.h>

#include <linux/init.h>
#include <linux/stat.h> 


MODULE_LICENSE("GPL");
MODULE_AUTHOR("Kalle & Olga Kuusamolainen"); 

static int __init init_this_module(void)
{
     	printk(KERN_INFO "mod1: init_this_module() called.\n");
	return 0;
}

static void __exit  shutdown_this_module(void)
{
     	printk(KERN_INFO "mod1: shutdown_this_module() called.\n");
}


module_init(init_this_module);
module_exit(shutdown_this_module);
File:Makefile
Code:
obj-m  := mod1.o

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

default:
	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
Note:
In the Makefile, there must be a TAB (tabulator) character before the
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
line.


Compile it (using the Makefile):
$ make

Load the module mod1.ko:
$ sudo insmod mod1.ko

Now check the system messages
$ dmesg | tail -10

[13408.233936] mod1: init_this_module() called.

Remove the module:
$ sudo rmmod mod1

Check again the system messages
$ dmesg | tail -10
or
$ dmesg | grep "mod1"

[13408.233936] mod1: init_this_module() called.
[13408.233937] mod1: shutdown_this_module() called.


Very important: Study these kernel developers' guides
http://www.futuredesktop.org/kernel.html Section: Driver and module programming.

Good luck
-----------------------

EDIT: Prerequisites to compile a kernel-module are:
$ sudo aptitude install build-essential gdb linux-headers-$(uname -r)

You may also need:
$ sudo aptitude install automake autoconf libtool
-----------------------

ps. This is howto install VMware Player and VirtualBox in/on Ubuntu 7.10 beta (gutsy gibbon).
http://www.futuredesktop.org/vmware/...yer-gutsy.html (just in case you need some love)
__________________
// moma
http://www.futuredesktop.org

Last edited by moma; December 19th, 2007 at 08:56 AM..
moma is offline   Reply With Quote
Old October 6th, 2007   #3
fr0ike
First Cup of Ubuntu
 
Join Date: Nov 2006
Beans: 2
Re: errors compiling modules

wow...
works perfectly ! thanks a lot !
fr0ike is offline   Reply With Quote

Bookmarks

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

Forum Jump


All times are GMT -4. The time now is 12:17 PM.


vBulletin ©2000 - 2010, Jelsoft Enterprises Ltd. Ubuntu Logo, Ubuntu and Canonical © Canonical Ltd. Tango Icons © Tango Desktop Project. bilberry