- 论坛徽章:
- 0
|
我的系统:
uname -a
2.6.9-34.EL #1 Fri Feb 24 16:44:51 EST 2006 i686 i686 i386 GNU Linux
gcc -v
gcc version 3.4.5 20051201 (Red Hat 3.4.5-2)
代码如下:
- #include <linux/init.h>
- #include <linux/module.h>
- #include <linux/kernel.h>
- MODULE_LICENSE("GPL");
- static int hello_init(void)
- {
- printk("Hello, world\n");
- return 0;
- }
- static void hello_exit(void)
- {
- printk("Goodbye, cruel world\n");
- }
- module_init(hello_init);
- module_exit(hello_exit);
复制代码
编译命令用:
gcc -D__KERNEL__ -DMODULE -I/lib/modules/2.6.9-34.EL/build/include/ -c sample.c
生成sample.o,然后insmod sample.o.
错误:
insmod: error inserting 'sample.o': -1 Invalid module format
在网上搜索一下,类似的问题最终归结2.6kernel的改变,还有一个可能是我的pc是i686,但安装版本选择的是i386 distribution (这个错误不太明确)。请大家指点一下!谢谢。 |
|