藍森林首頁 | 返回主頁 | 本站地圖 | 站內搜索 | 聯繫信箱 |
 您目前的位置:首頁 > 自由軟件 > 技術交流 > 應用編程


    

藍森林 http://www.lslnet.com 2006年6月6日 10:18


內核模塊編程的hello world程序運行出錯,求助

[root@darkdaemon kernel_module]# cat hello.c
#include<linux/kernel.h>;
#include<linux/module.h>;

#if CONFIG_MODVERSIONS==1
#define MODVERSIONS
#include<linux/modversions.h>;
#endif


int init_module()
{
   printk("hello,world - this is the kernel speaking\n");

   return 0;
}

void cleanup_module()
{
   printk("Short is the life of a kernel module\n");
}

[root@darkdaemon kernel_module]#

gcc -Wall -DMODULE -D__kernel__ -DLINUX -c hello.c

編譯後

[root@darkdaemon kernel_module]# /sbin/insmod hello.o
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.
[root@darkdaemon kernel_module]#


請問該如何解決這個問題?

內核模塊編程的hello world程序運行出錯,求助

頂啊

請教各位大大

內核模塊編程的hello world程序運行出錯,求助

這個不是說你編譯的內核版本和你所用的內核版本不同嗎?
仔細看看你的那些頭文件和那些條件編譯語句。
MODVERSIONS是什麼值?

內核模塊編程的hello world程序運行出錯,求助

好像要在模塊中加入version的信息就可以了

內核模塊編程的hello world程序運行出錯,求助

兩個問題:
1、需要在init_module中加入這行代碼
MODULE_LICENSE("GPL");
否則會報license錯
2、編譯的時候需要指定kernel的頭文件路徑
所以要這樣編譯

gcc -Wall -DMODULE -D__kernel__ -DLINUX -c hello.c  -I/usr/src/linux-2.4.18-14/include/

否則會報版本錯

內核模塊編程的hello world程序運行出錯,求助

請大家幫忙:
我調試過,這回內核能夠編譯通過,但是insmod hello.o沒有顯示
編譯時候出錯:
implicit declaration of function 'printk_R1b7d4074'
不知道為什麼找不到printk,還請指挑明路

內核模塊編程的hello world程序運行出錯,求助

這個問題,我最近也遇見了,我幫你頂一下吧
這樣我自己也可以學習學習..

不知道是否有高人原意回答一下的.



Copyright © 1999-2000 LSLNET.COM. All rights reserved. 藍森林網站 版權所有。 E-mail : webmaster@lslnet.com