Results 1 to 1 of 1
Hello,
I'm trying to build a module for the Linux Kernel. To explain my problem, I've taken the most simple example : just 2 files, hello.c and Makefile.
hello.c
Code:
...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 09-14-2010 #1Just Joined!
- Join Date
- Sep 2010
- Posts
- 1
Error when using 'O=' option to build kernel module
Hello,
I'm trying to build a module for the Linux Kernel. To explain my problem, I've taken the most simple example : just 2 files, hello.c and Makefile.
hello.c
MakefileCode:#include <linux/module.h> #include <linux/kernel.h> int init_module(void) { printk(KERN_INFO "init_module() called\n" ); return 0; } void cleanup_module(void) { printk(KERN_INFO "cleanup_module() called\n" ); }
Code:obj-m += hello.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
When I compile with the above makefile, everything is fine.
Now, what I would like to do it to redirect to output files to some other directory in order to avoid polluting my source directory. For this, I use the 'O=' option as explained in the kernel docs like this :
Unfortunately, I'm unable to compile using this option. Here is the output I get :Code:all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) O=$(PWD)/objects modules
With the V=1 option, I get the following subcall to make that is made :Code:make -C /lib/modules/2.6.32-21-generic/build M=/home/username/hello O=/home/username/hello/objects modules make[1]: Entering directory `/usr/src/linux-headers-2.6.32-21-generic' ERROR: Kernel configuration is invalid. include/linux/autoconf.h or include/config/auto.conf are missing. Run 'make oldconfig && make prepare' on kernel src to fix it. WARNING: Symbol version dump /home/username/hello/objects/Module.symvers is missing; modules will have no dependencies and modversions. CC [M] /home/username/hello/hello.o [.....many errors like the folllowing....] In file included from /usr/src/linux-headers-2.6.32-21-generic/arch/x86/include/asm/percpu.h:45, from /usr/src/linux-headers-2.6.32-21-generic/arch/x86/include/asm/current.h:5, from /usr/src/linux-headers-2.6.32-21-generic/arch/x86/include/asm/processor.h:15, from /usr/src/linux-headers-2.6.32-21-generic/include/linux/prefetch.h:14, from /usr/src/linux-headers-2.6.32-21-generic/include/linux/list.h:6, from /usr/src/linux-headers-2.6.32-21-generic/include/linux/module.h:9, from /home/username/hello/hello.c:1: /usr/src/linux-headers-2.6.32-21-generic/include/linux/kernel.h:185: warning: conflicting types for built-in function ‘snprintf’ /usr/src/linux-headers-2.6.32-21-generic/include/linux/kernel.h:187: warning: conflicting types for built-in function ‘vsnprintf’ In file included from /usr/src/linux-headers-2.6.32-21-generic/arch/x86/include/asm/string.h:2, [.....] /bin/sh: scripts/basic/fixdep: not found make[3]: *** [/home/username/hello/hello.o] Error 127 make[2]: *** [_module_/home/username/hello] Error 2 make[1]: *** [sub-make] Error 2 make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-21-generic' make: *** [all] Error 2
Code:make -C /home/username/hello/objects \ KBUILD_SRC=/usr/src/linux-headers-2.6.32-21-generic \ KBUILD_EXTMOD="/home/username/hello" -f /usr/src/linux-headers-2.6.32-21-generic/Makefile \ modules
I looked at the main Kernel Makefile and this is the submake command I would expect.
Note that the include/linux/autoconf.h and include/config/auto.conf exist (+ there is no error when not using 'O=' option). After investigation, the "ERROR: Kernel configuration is invalid." can be explained because the current directory is '/home/username/hello/objects' and the search path is relative to this folder...
Has anyone else successfully used the 'O=' option before? Am I missing something?
Many thanks in advance for your help.


Reply With Quote
