当前位置: 技术问答>linux和unix
insmod kernel error
来源: 互联网 发布时间:2015-10-30
本文导语: hello.c: #define MODULE 2.4.20-8smp #include int init_module(void){printk("Hello World!");return 0;} void cleanup_module(void){printk("Goodbye cruel world!");} After I compile a hello.c file into hello.o, I insmod hello.o but find the error: hello.o: kernel-mo...
hello.c:
#define MODULE 2.4.20-8smp
#include
int init_module(void){printk("Hello World!");return 0;}
void cleanup_module(void){printk("Goodbye cruel world!");}
After I compile a hello.c file into hello.o, I insmod hello.o
but find the error:
hello.o: kernel-module version mismatch
hello.o was compiled for kernel version 2.4.20
while this kernel is version 2.4.20-8.
why the error ? how to solve it?
thanks
#define MODULE 2.4.20-8smp
#include
int init_module(void){printk("Hello World!");return 0;}
void cleanup_module(void){printk("Goodbye cruel world!");}
After I compile a hello.c file into hello.o, I insmod hello.o
but find the error:
hello.o: kernel-module version mismatch
hello.o was compiled for kernel version 2.4.20
while this kernel is version 2.4.20-8.
why the error ? how to solve it?
thanks
|
编译的内核版本和现在运行的不一致
简单的方法,修改
/usr/include/linux/version.h
中
UTS_RELEASE 为 2.4.20-8
简单的方法,修改
/usr/include/linux/version.h
中
UTS_RELEASE 为 2.4.20-8
|
/* How to compile:
* gcc -I /usr/src/linux-2.4/include -DMODULE -D__KERNEL__ -O2 -c hello.c
*/
#ifndef MODULE
#define MODULE
#endif
#ifndef __KERNEL__
#define __KERNEL__
#endif
#include
#include
int init_module(void)
{
printk(KERN_ALERT "Hello World!n");
return 0; // Must return 0!
}
void cleanup_module(void)
{
printk(KERN_ALERT "Goodbye world!n");
}
MODULE_LICENSE("GPL"); // Avoid "no license" warning.
* gcc -I /usr/src/linux-2.4/include -DMODULE -D__KERNEL__ -O2 -c hello.c
*/
#ifndef MODULE
#define MODULE
#endif
#ifndef __KERNEL__
#define __KERNEL__
#endif
#include
#include
int init_module(void)
{
printk(KERN_ALERT "Hello World!n");
return 0; // Must return 0!
}
void cleanup_module(void)
{
printk(KERN_ALERT "Goodbye world!n");
}
MODULE_LICENSE("GPL"); // Avoid "no license" warning.
|
更简单的方法:在insmod的时候加上-f参数