magic 下modules编程的问题!!
我在做操作系统课设,照书copy了一个hello world的模块程序 在magic下编译不能通过源程序如下:#include <linux/module.h>
#if defined(CONFIG_SMP)
#define __SMP__
#endif
/*#if defined(CONFIG_MODVERSIONS) //这里源程序没注释掉,如果不注释
#define MODVERSIONS //掉,编译时会提示找不到modversions.h这个
#include <linux/modversions.h> //文件或目录,然后不能生成hello.o
#endif*/
#include <linux/kernel.h>
static__init int init_module(void)
{
printk(KERN_DEBUG "Hello, kernel!\n" );
return 0;
}
static __exit void cleanup_module(void)
{
printk(KERN_DEBUG "Good-bye, kernel!\n" );
}
编译命令如下
gcc -D__KERNEL__ -I/usr/src/linux/include -DMODULE -Wall -O2 -c hello.c -o hello.o
能通过,但是有很多warnings:
如下
In file included from /usr/src/linux/include/asm/processor.h:18,
from /usr/src/linux/include/asm/thread_info.h:16,
from /usr/src/linux/include/linux/thread_info.h:21,
from /usr/src/linux/include/linux/spinlock.h:12,
from /usr/src/linux/include/linux/capability.h:45,
from /usr/src/linux/include/linux/sched.h:7,
from /usr/src/linux/include/linux/module.h:10,
from hello.c:1:
/usr/src/linux/include/asm/system.h: In function `__set_64bit_var':
/usr/src/linux/include/asm/system.h:193: warning: dereferencing type-punned pointer will break strict-aliasing rules
/usr/src/linux/include/asm/system.h:193: warning: dereferencing type-punned pointer will break strict-aliasing rules
hello.c: At top level:
hello.c:14: warning: static declaration of 'init_module' follows non-static declaration
/usr/src/linux/include/linux/module.h:48: warning: previous declaration of 'init_module' was here
hello.c:20: warning: static declaration of 'cleanup_module' follows non-static declaration
/usr/src/linux/include/linux/module.h:49: warning: previous declaration of 'cleanup_module' was here
hello.c:14: warning: 'init_module' defined but not used
hello.c:20: warning: 'cleanup_module' defined but not used
然后insmod hello.o
提示错误如下:insmod: error inserting 'hello.o': -1 Invalid module format
哪位能帮忙解下惑,或者给点magic下编译modules的资料,谢谢了!!! ^_^
看来我们做的课程设计差不多都~~
2.4.*的内核insmod是*.o
但是2.6的内核模块名是 *.ko
具体的看着个网页
http://www.tldp.org/LDP/lkmpg/2.6/html/x204.htm
我就是照这个做的
呵呵,我也是菜鸟,只不过遇到过这个问题,解决了
希望能帮到你 汗
猛然发现楼主的ID这么眼熟的说.....
HUST CS大牛? 呵呵 谢谢 我已经找到解决办法了 你给的帖子里的东西我有那本原书了 :)
你要不要?
你去过cs版吗? 欢迎来cs版玩哦
你看我这样子就是小菜
谢谢哈 :) 我也是cs的...
只不过不泡bbs
呵呵 :oops: ,惭愧惭愧,我也是CS的,不过还没这么玩过……
页:
[1]