在Linux-2.6.3中加载内核模块的问题。UP有分!

tianxiangyuan 2004-04-06 01:18:47
我使用的Linux是Mandrake10,内核为Linux-2.6.3,module-init-tools version 3.0-pre9,在其下编写一个内核模块:

#define MODULE
#define __KERNEL__
#include <linux/module.h>
int init_module()
{
return 0;
}
void cleanup_module()
{

}
使用如下命令编译:
gcc -c -I/usr/src/linux-2.6/include -o test.ko test.c
在使用如下命令加载时:
insmod test.ko
出现如下错误:
insmod: error inserting 'test.ko': -1 Invalid module format

请问各位大虾:该如何解决?
...全文
74 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xjl1980_81 2004-04-09
  • 打赏
  • 举报
回复
由于本人对编译命令不是很明白,所以当初就这样做了
将en3.c请在drivers目录下,然后使用以下命令编译就OK了
gcc -Wp,-MD,drivers/.en3.o.d -D__KERNEL__ -Iinclude -Wstrict-prototypes -Wno-trigraphs -O2 -fno-strict-aliasing -fno-common -pipe -mpreferred-stack-boundary=2 -Iinclude/asm-i386/mach-default -nostdinc -iwithprefix include -DMODULE -DKBUILD_BASENAME=en3 -DKBUILD_MODNAME=en3 -c -o drivers/en3.o drivers/en3.c

当然了,这条编译命令要根据具体环境决定,只作参考
2003rainbow 2004-04-09
  • 打赏
  • 举报
回复
捧場,問題不會,給點分,outdachong
tianxiangyuan 2004-04-09
  • 打赏
  • 举报
回复
自己顶
xjl1980_81 2004-04-08
  • 打赏
  • 举报
回复
我以前也遇到过此问题
是编译的原因

4,465

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 内核源代码研究区
社区管理员
  • 内核源代码研究区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧