compile a hello world kernel mod.
hi I am following linux device drivers 3rd edition. running a 2.6.14 kernel in slackware 10.2 I have written the obligatory hello world program but,I can't get it to compile... i tried
Code:
obj-m := hello.o Code:
CC=gcc CFLAGS := -Wall -DMODULE -D__KERNEL__ -DLINUX INCLUDES := /usr/include hello.o: hello.c $(CC) $(CFLAGS) -c hello.c Code:
#include <linux/init.h> #include <linux/module.h> MODULE_LICENSE("Dual BSD/GPL"); static int hello_init(void){ printk(KERN_ALERT"Who's Your Daddy?\n"); return 0; } static void hello_exit(void){ printk(KERN_ALERT"Bye,Bye\n"); } module_init(hello_init); module_exit(hello_exit); |
Quote:
I think you are skipping some steps. You should learn a bit on make with not-kernel code. Anyway, you can help yourself by inserting your module in the kernel source tree, so you don't have to bother with makefile and the options passed to GCC for creating a module example: put your source file in /home/me/ldd3 call it hello.c then Code:
cd /usr/src/linuxxxx Code:
echo "obj-m += ldd3" >> Makefile You add hello2.o to the list (+=) of modules the top makefile has to compile. Code:
cd ldd3 Code:
cd /usr/src/linux |
hi,
To compile a kernel module in 2.6 kernel you need Makefile Quote:
|
thnks gents.
After reading your posts and then doing a bit more reading my first modules have been built on both 2.4* and 2.6* I'm not totally unfamiliar with make but it is a weakness that I'm working on. |
I come back on what I said, make is important this is true.
But the makefile of the kernel is quite complex, its syntax is very optimized and you will get a big headache reading it. If you put your files in the source tree and use the makefile of the kernel guys, the parameters of gcc will always be correct among different kernels (still the module interface has changed, you might need the file from allessandro sysreference.h or something like this) and you probably don't need to look so much in the makefiles. You can concentrate on driver coding which is also a very tough task. Some kernel coding needs an average level, others need a very good understanding of the whole thing. good luck |
true I would very much prefer to concentrate on Kernel code and understanding how the computers resources are made available to programs via the kernel etc..
but I have a question.. Quote:
:confused: where does hello2.o come from ? |
I intentionnaly introduce a typo to see if you were following ;)
its not hello2.o but hello.o edit: error in post #2 corrected |
:cool:
Good answer. |
All times are GMT -5. The time now is 12:04 AM. |