免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2270 | 回复: 3
打印 上一主题 下一主题

linux设备驱动书中第一个helloworld程序不能编译的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-09-29 21:24 |只看该作者 |倒序浏览
下面是代码 hello.c
#ifndef __KERNEL__
        #define __KERNEL__
#endif
#ifndef MODULE
        #define MODULE
#endif
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>

static int hello_init(void)
{
        printk(KERN_ALERT "Hello, The fucking crazy world\n");
        return 0;
}

static void hello_exit(void)
{
        printk(KERN_ALERT "Bye, The fucking crazy world!\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("albcamus <albcamus@163.com>");
MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_SUPPORTED_DEVICE("testdevice");
下面是编译用的makefile
obj-m := hello.o
KERNELBUILD := /lib/modules/`uname -r`/build
default:
        make -C $(KERNELBUILD) M=$(shell pwd) modules
clean:
        rm -rf *.o .*.cmd *.ko *.mod.c .tmp_versions
我的内核版本是 2.4.20-8  ,用的red hat 9,没有从新编译内核,因为我用的vmware编译内核需要/usr 文件系统有>10G的空间,编译时报错了
我的
/usr/include/linux/version.h 中的
#define UTS_RELEASE "2.4.20"
改为
#define UTS_RELEASE "2.4.20-8"

错误是
/usr/src/linux-2.4.20-8/include/linux/kernel.h:68: parse error before numeric constant
/usr/src/linux-2.4.20-8/include/asm/processor.h:82: parse error before numeric constant
/usr/src/linux-2.4.20-8/include/linux/module.h:187: invalid suffix on integer constant
还有很多类似错误,大侠们帮忙看看到底应该怎么解决

论坛徽章:
0
2 [报告]
发表于 2006-09-30 09:56 |只看该作者
我只知道2.4的内核你用2.6的编译方式,会不会有问题?
2.4没有*.ko吧?2.6下才有

论坛徽章:
0
3 [报告]
发表于 2006-09-30 10:57 |只看该作者
别用2.4了, 现在全都是2.6的天下。

ps. 如果你非用2.4编译这个例子, 试试这样行不(首先装上kernel-devel  rpm包):
gcc -I /usr/src/linux/include -c -o hello.o

论坛徽章:
0
4 [报告]
发表于 2006-09-30 12:06 |只看该作者

编译还是出错

gcc -I /usr/src/linux/include -c -o hello.o -g hello.c 出现这样的错误
hello.c: In function `hello_init':
hello.c:14: `KERN_ALERT' undeclared (first use in this function)
hello.c:14: (Each undeclared identifier is reported only once
hello.c:14: for each function it appears in.)
hello.c:14: parse error before string constant
hello.c: In function `hello_exit':
hello.c:20: `KERN_ALERT' undeclared (first use in this function)
hello.c:20: parse error before string constant
hello.c: At top level:
hello.c:26: parse error before "DRIVER_DESC"
那位有在2.4上编译的方法,现在我想重新安装一个debain 将vmware文件定义很大,以后就可以编译了,可惜debain的文件有 5个iso文件8.5G,太大了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP