Results 1 to 5 of 5
Hello friends! I'm following the guide "The linux kernel module programming guide". I'm trying with the hello world mode, wich code is this:
Code:
#include <linux/module.h>
#include <linux/kernel.h>
int init_module(void)
...
- 01-05-2011 #1Just Joined!
- Join Date
- Nov 2009
- Posts
- 72
[SOLVED] hello world module problem
Hello friends! I'm following the guide "The linux kernel module programming guide". I'm trying with the hello world mode, wich code is this:
The original make file in the guide is wrong. This is the codeCode:#include <linux/module.h> #include <linux/kernel.h> int init_module(void) { printk(KERN_INFO "Hello world 1.\n"); return 0; } void cleanup_module(void) { printk(KERN_INFO "Goodbye world 1.\n"); }
Which tells "Nothing to be done for all"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
So i found this makefile in the web:
Which trhows this error message:Code:obj-m += hello.o KDIR := /lib/modules/2.6.32-27-generic/build PWD := $(/home/jesus/pruebas/c/) default: make -C $(KDIR) SUBDIRS=$(PWD) modules
Please help!!!Code:make -C /lib/modules/2.6.32-27-generic/build SUBDIRS= modules make[1]: se ingresa al directorio `/usr/src/linux-headers-2.6.32-27-generic' CHK include/linux/version.h CHK include/linux/utsrelease.h SYMLINK include/asm -> include/asm-x86 make[2]: *** No hay ninguna regla para construir el objetivo `kernel/bounds.c', necesario para `kernel/bounds.s'. Alto. make[1]: *** [prepare0] Error 2 make[1]: se sale del directorio `/usr/src/linux-headers-2.6.32-27-generic' make: *** [default] Error 2
Many thanks!
- 01-05-2011 #2Just Joined!
- Join Date
- Nov 2009
- Posts
- 72
I found the error for the first Makefile. After "all:" there must be a "tab" instead of spaces:
With this makefile, i get this error message:Code:obj-m += hello.o all: make -C /lib/modules/2.6.32-27-generic/build M=/home/jesus/pruebas/c modules clean: make -C /lib/modules/2.6.32-27-generic/build M=/home/jesus/pruebas/c clean
Code:make -C /lib/modules/2.6.32-27-generic/build M=/home/jesus/pruebas/c modules make[1]: se ingresa al directorio `/usr/src/linux-headers-2.6.32-27-generic' make[2]: *** No hay ninguna regla para construir el objetivo `/home/jesus/pruebas/c/hello.c', necesario para `/home/jesus/pruebas/c/hello.o'. Alto. make[1]: *** [_module_/home/jesus/pruebas/c] Error 2 make[1]: se sale del directorio `/usr/src/linux-headers-2.6.32-27-generic' make: *** [all] Error 2
- 01-08-2011 #3Just Joined!
- Join Date
- Oct 2008
- Posts
- 4
Good day.
I also had issue compiling hello world module.
This helped in my case.
first manually write your Makefile, dont copy and paste from tutorial.
Actually daches ,and another characters are differ.
obj-m , −C , −r
The dache signs here copied from your post and are differ than ascii dash '-' .
Second.
I don't know much about kernel policy of compiling modules, but some modules
requare Kbuild file, others dont.
So try this way.
Cut obj-m += hello.o string from your Makefile, create new Kbuild file
in the same dir and save obj-m += hello.o string in Kbuild file and then compile.
- 01-08-2011 #4Just Joined!
- Join Date
- Oct 2008
- Posts
- 4
Good day.
I also had issue compiling hello world module.
This helped in my case.
first manually write your Makefile, dont copy and paste from tutorial.
Actually daches ,and another characters are differ.
obj-m , −C , −r
The dache signs here copied from your post and are differ than ascii dash '-' .
Second.
I don't know much about kernel policy of compiling modules, but some modules
requare Kbuild file, others dont.
So try this way.
Cut obj-m += hello.o string from your Makefile, create new Kbuild file
in the same dir and save obj-m += hello.o string in Kbuild file and then compile.
- 01-08-2011 #5Just Joined!
- Join Date
- Nov 2009
- Posts
- 72
Hi heliks!! Many thanks!! This make file i have just found, works properly too!
Code:ifeq ($(KERNELRELEASE),) # Assume the source tree is where the running kernel was built # You should set KERNELDIR in the environment if it's elsewhere KERNELDIR ?= /lib/modules/2.6.32-27-generic/build # The current directory is passed to sub-makes as argument PWD := /home/jesus/pruebas/module2/ modules: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules modules_install: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install clean: rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions .PHONY: modules modules_install clean else # called from kernel build system: just declare what our modules are obj-m := hello.o obj-m := hello2.o endif



