LinuxSir.cn,穿越时空的Linuxsir!

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

请问这个makefile为什么出错?

[复制链接]
发表于 2006-2-14 15:39:24 | 显示全部楼层 |阅读模式
我copy了一个内核模块的例程:

//hello.c

#include <linux/module.h>
#include <linux/kernel.h>

#if CONFIG_MODVERSIONS==1
#define MODVERSIONS
#include <linux/modversions.h>
#endif

int init_module(void)
{
printk("<1>Hello world 1.\n");
return 0;
}
void cleanup_module(void)
{
printk("Goodbye world 1.\n");
}


//makefile内容如下
CC=gcc
MODCFLAGS := -Wall -DMODULE -D__KERNEL__ -Dlinux
hello.o: hello.c /usr/include/linux/version.h
$(CC) $(MODCFLAGS) -c hello.c

make时出现如下错误
makefile:4: *** missing separator.  Stop.

请问怎么回事?
发表于 2006-2-14 15:59:41 | 显示全部楼层
Post by pink_tulip

hello.o: hello.c /usr/include/linux/version.h
$(CC) $(MODCFLAGS) -c hello.c



比较文件之后,
在要运行的命令前应该有一个tab制表符
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-2-14 16:24:24 | 显示全部楼层
可以make了,但是:

[root@localhost test]# make
gcc -Wall -DMODULE -D__KERNEL__ -DLinux -c hello.c
In file included from /usr/include/linux/module.h:10,
                 from hello.c:2:
/usr/include/linux/config.h:5:2: error: #error Incorrectly using glibc headers for a kernel module
hello.c: In function ‘init_module’:
hello.c:11: warning: implicit declaration of function ‘printk’
make: *** [hello.o] Error 1
回复 支持 反对

使用道具 举报

发表于 2006-2-14 20:55:01 | 显示全部楼层
内核编程好像不可以调用外部函数库的。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-2-14 21:11:26 | 显示全部楼层
所有看到的教程都是这么写的。
回复 支持 反对

使用道具 举报

发表于 2006-2-15 00:29:46 | 显示全部楼层
是么?我是做项目得出的经验而已。
回复 支持 反对

使用道具 举报

发表于 2006-2-15 00:48:31 | 显示全部楼层
makefile 应该这样写:
[php]obj-m += hello.o

all:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean[/php]
回复 支持 反对

使用道具 举报

发表于 2006-2-15 08:52:40 | 显示全部楼层
如果你使用的是外部的函数库,那系统中只安装了内核时,怎么让它运行?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-2-15 12:52:05 | 显示全部楼层
这几个.h文件都是内核里的
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-2-15 14:31:07 | 显示全部楼层
还有,我很奇怪出错信息中有乱码。

[root@localhost test]# make
gcc -O6 -Wall -DCONFIG_KERNELD -DMODULE -D__KERNEL__ -DLinux -c hello.c
In file included from /usr/include/linux/module.h:10,
                 from hello.c:2:
/usr/include/linux/config.h:5:2: error: #error Incorrectly using glibc headers for a kernel module
hello.c: In function ‘init_module’:
hello.c:11: warning: implicit declaration of function ‘printk’
make: *** [hello.o] Error 1
回复 支持 反对

使用道具 举报

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

本版积分规则

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