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

Ubuntu 9.10 is out!!!

When downloading Ubuntu 9.10 please consider using bittorrent to get your copy of Ubuntu.

The Ubuntu Developers Summit for Lucid Lynx will be held the week of 16-Nov-2009 till 20-Nov-2009 in Dallas, TX USA. Visit the the Ubuntu wiki for more information about UDS and how to participate remotely.

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
Prev Previous Post   Next Post Next
Old October 6th, 2007   #2
moma
Quad Shot of Ubuntu
 
moma's Avatar
 
Join Date: Jan 2006
Location: Grønland,Oslo
Beans: 482
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
Code::Blocks IDE: http://i1.no/08fo/

Last edited by moma; December 19th, 2007 at 08:56 AM..
moma 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 10:18 PM.


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