linux/module.h
i'm going to learn kernel programming based on LLD2 book.
there is a hello module example in the chapter 2 that i can't compile it with gcc. here's the code: Code:
#define MODULE Code:
root@ubuntu:/home/devilboy/Desktop# gcc -c hello.c |
Hi Devil Boy,
You need to build the module within the Context of the Linux tree. By default, the compiler will look for user-space headers in /usr/include. There ARE some linux headers there (/usr/include/linux), but module.h is not one of them, as it deals with kernel constructs directly. In short, you need a Makefile. Also, get rid of the #define MODULE. save the following to a file called Makefile and run make: Code:
obj-m += foo.o Given that you are using Ubuntu, you probably already have the kernel headers installed at /usr/src/linux-headers-$(uname -r). module.h lives here: Code:
jameson@aqua:~$ ls /usr/src/linux-headers-$(uname -r)/include/linux/module.h |
i did what you said i created a directory named header and i put the Makefile in it, but i got this error:
Code:
root@ubuntu:/home/devilboy/Desktop/Header# make |
Ah, your module is called hello.c, not foo.c. You'd need to change that one first line of the makefile, from foo.o to hello.o.
|
i did what you said and i could compile it . but i can't insert it as module:
Code:
root@ubuntu:/home/devilboy/Desktop# insmod ./hello.o |
You need to insert the Kernel Object (.ko) file, hello.ko. hello.o is intermediary object code.
|
i'm sorry, i didn't get it.what should i do exactly?
|
hello.o is not the file you want to insert. You want to insert the kernel module, which is hello.ko.
Code:
insmod hello.ko |
i did insert the hello.ko but nothing happend!!!
Code:
root@ubuntu:/home/devilboy/Desktop# insmod ./hello.ko |
Run dmesg and you'll see it.
|
tanX
|
i'm having the same problem with init.h
hello.c: Code:
#include <linux/init.h> Code:
root@ubuntu:/home/devilboy/Desktop# gcc -c hello.c Code:
obj-m += hello.c Code:
root@ubuntu:/home/devilboy/Desktop# make |
You shouldn't be running gcc directly. That's the problem. Just run make. Also, that won't work at this point because you have an error in your makefile.
Code:
obj-m += hello.c Code:
obj-m += hello.o |
thank you
|
Quote:
Thnx. |
All times are GMT -5. The time now is 02:02 AM. |