|
我在做操作系统课设,照书copy了一个hello world的模块程序 在magic下编译不能通过源程序如下:
[code:1]#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" );
}[/code:1]
编译命令如下
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的资料,谢谢了!!! |
|