Skip to main content

Thread: compiling a kernel module


hi! need learn write kernel modules. using documentation linux kernel source (file <linux_src>/documentation/kbuild/modules.txt) , tldp project (http://www.tldp.org/ldp/lkmpg/2.6/html/index.html)
have pre-installed linux headers kernel.
created directory 2 files:

az@az-ubuntu:/mnt/misc/code/my_module_2$ ls
hello.c makefile

az@az-ubuntu:/mnt/misc/code/my_module_2$ cat ./hello.c
/*
* hello.c - simplest kernel module.
*/
#include <linux/module.h> /* needed modules */
#include <linux/kernel.h> /* needed kern_info */

int init_module(void)
{
printk(kern_info "hello world 1.\n");

/*
* non 0 return means init_module failed; module can't loaded.
*/
return 0;
}

void cleanup_module(void)
{
printk(kern_info "goodbye world 1.\n");
}

az@az-ubuntu:/mnt/misc/code/my_module_2$ cat ./makefile
obj-m = hello.o
kversion = $(shell uname -r)
all:
make -c /lib/modules/$(kversion)/build m=$(pwd)
clean:
make -c /lib/modules/$(kversion)/build m=$(pwd) clean
looks have done correct, here's happens when try make:

az@az-ubuntu:/mnt/misc/code/my_module_2$ make
make: nothing done `all'.
the required directory linux headers exists:

az@az-ubuntu:/mnt/misc/code/my_module_2$ ls /lib/modules/`uname -r`/build
arch crypto drivers fs init kbuild kernel makefile module.symvers samples security source ubuntu virt
block documentation firmware include ipc kconfig lib mm net scripts sound tools usr

help!

do have tabs in front of make commands in makefile? note

makefile:
code:
obj-m = hello.o kversion = $(shell uname -r) all: make -c /lib/modules/$(kversion)/build m=$(pwd) clean: make -c /lib/modules/$(kversion)/build m=$(pwd) clean
code:
$ make make: nothing done `all'.
makefiles sensitive indentation....

new makefile:
code:
obj-m = hello.o kversion = $(shell uname -r) all:   make -c /lib/modules/$(kversion)/build m=$(pwd) clean:   make -c /lib/modules/$(kversion)/build m=$(pwd) clean
code:
$ make make -c /lib/modules/3.0.0-9-generic/build m=/home/niall/desktop/temp make[1]: entering directory `/usr/src/linux-headers-3.0.0-9-generic'   building modules, stage 2.   modpost 1 modules make[1]: leaving directory `/usr/src/linux-headers-3.0.0-9-generic'


Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Packaging and Compiling Programs compiling a kernel module


Ubuntu

Comments

Popular posts from this blog

Joomla 3.3 Installation Error message - Joomla! Forum - community, help and support

Multilanguage infinite redirect loop error. - Joomla! Forum - community, help and support

trim media limit reached