LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 734|回复: 3

请教

[复制链接]
发表于 2005-3-29 13:35:48 | 显示全部楼层 |阅读模式
:thank
插入2.6.5的内核模块的问题:
hello.c

#define MODULE
#define KERNEL
#include <linux/module.h>
int init_module(void){printk("<1>hello!world\n");return 0;}
void cleanup_module(void) {printk("<1>goodbye!world\n");}

编译hello.c通过:
root]#gcc -c hello.c
插入出错:
root]#insmod ./hello.o
insmod:error inserting './hello.o':-l(还是1??)Invalid module format

改写为:
hello.c

#define MODULE
#define __KERNEL__
#include <linux/module.h>
int init_module(void){printk("<1>hello!world\n");return 0;}
void cleanup_module(void) {printk("<1>goodbye!world\n");}

编译出错:
root]#gcc -c hello.c
In file include from /usr/include/linux/module.h:10,
                        from hello.c:3
/usr/include/linux/config.h:5.2: #error Incorrectly using glibc headers for a kernel module


谢谢
发表于 2005-3-30 09:01:35 | 显示全部楼层
编译方法错了.
看内核源代码目录下
Documentation/kbuild/modules.txt
里面有很详细的说明.
回复 支持 反对

使用道具 举报

发表于 2005-3-30 09:05:21 | 显示全部楼层
Post by jorson
:thank
插入2.6.5的内核模块的问题:
hello.c

#define MODULE
#define KERNEL
#include <linux/module.h>
int init_module(void){printk("<1>hello!world\n");return 0;}
void cleanup_module(void) {printk("<1>goodbye!world\n");}

编译hello.c通过:
root]#gcc -c hello.c
插入出错:
root]#insmod ./hello.o
insmod:error inserting './hello.o':-l(还是1??)Invalid module format

改写为:
hello.c

#define MODULE
#define __KERNEL__
#include <linux/module.h>
int init_module(void){printk("<1>hello!world\n");return 0;}
void cleanup_module(void) {printk("<1>goodbye!world\n");}

编译出错:
root]#gcc -c hello.c
In file include from /usr/include/linux/module.h:10,
                        from hello.c:3
/usr/include/linux/config.h:5.2: #error Incorrectly using glibc headers for a kernel module


谢谢


Makefile 应如下:
obj-m:=hello.o
default:
[tab]make -C /lib/modules/`uname -r`/build M=`pwd`

然后make就可以了
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-3-30 12:41:49 | 显示全部楼层
呵呵,谢谢,我试一试
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表