我不会用makefile的
以前gcc -I usr/src/linux-2.4.18-14/include -c hello.c时出现"kernel-module version mismatch"的问题.
看了精华贴,用这个命令
gcc -c -DMODULE -D__KERNEL__ -DLINUX -I/usr/src/linux-2.4.18-14/include hello.c
结果:hello.c:1:1: warning: "MODULE" redefined
hello.c:1:1: warning: this is the location of the previous definition
再输入命令insmod ./hello.o
结果:
insmod: a module named hello already exists
这是什么意思?
MODULE_LICENSE("GPL");
[/code:1]
version.h will be included automatically.
need check the /usr/src/linux/include. whether the /usr/src/linux is u linux source code dir. must match. the default rh kernel source code will add 2.xx.xcustom. need remove that custom.
since there are many difference between each kernel version. kernel have to use the kernel version code to make sure u will call correct functions.
write makefile is a good habit. i bet my makefile can work.
for the "already exist " problem, u already insert the module to kernel. u can use lsmod to check it. and u can use rmmod to remove it.
btw, i go to cinema to see the MATRIX II yesterday night. so do not reply the posts in time. sorry.
strange, if i do not include it, i compile it with warning, although get .o as well. anyway u need that for kmalloc. i can not image a serious module do not have kmalloc.
我的源程序是这样的,是不是有问题呀?
#define MODULE
#include <linux/module.h>
int init_module(void) {printk("<1>hello world\n");return 0;}
void cleanup_module(void){printk("<1>goodbye\n");}
用这个命令:gcc -I usr/src/linux-2.4.18-14/include -c hello.c
没问题,再用命令:insmod ./hello.o
返回:hello.o is compile for kernel version 2.4.9-9
while this kernel version is 2.4.18-14
我想问的是是不是程序本身的写法只能用于2.4.9-9