LinuxSir.cn,穿越时空的Linuxsir!

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

初学编写驱动就被打击了 各位进来指点一下吧

[复制链接]
发表于 2006-9-23 17:27:00 | 显示全部楼层 |阅读模式
代码很简单
  1. #include <linux/init.h>
  2. #include <linux/module.h>
  3. MODULE_LICENSE("DUAL BSD/GPL");
  4. static int hello_init(void)
  5. {
  6.         printk(KERN_ALERT"hello,world\n");
  7.         return 0;
  8. }
  9. static void hello_exit(void)
  10. {
  11.         printk(KERN_ALERT"Good bye,cruel world\n");
  12. }
  13. module_init(hello_init);
  14. module_init(hello_exit);
  15. ~
复制代码

编译就不行了
# gcc -c hello.c
hello.c: In function 'hello_init':
hello.c:7: error: 'KERN_ALERT' undeclared (first use in this function)
hello.c:7: error: (Each undeclared identifier is reported only once
hello.c:7: error: for each function it appears in.)
hello.c:7: error: syntax error before string constant
hello.c: In function 'hello_exit':
hello.c:13: error: 'KERN_ALERT' undeclared (first use in this function)
hello.c:13: error: syntax error before string constant
hello.c: At top level:
hello.c:17: warning: initialization from incompatible pointer type
是什么原因请各位赐教
发表于 2006-9-23 20:27:24 | 显示全部楼层
去找一本叫 <Linux设备驱动程序>(Linux Device Driver) 的书, 把里面关于如果编译这个例程的部分好好读一下
回复 支持 反对

使用道具 举报

发表于 2006-9-23 21:32:09 | 显示全部楼层
www.tldp.org 上的 <The Linux Kernel Module Programming Guide> 也可以看一看
回复 支持 反对

使用道具 举报

发表于 2006-9-24 00:03:46 | 显示全部楼层
直接告诉他是使用的编译选项问题就行了吧!
回复 支持 反对

使用道具 举报

发表于 2006-9-24 01:39:54 | 显示全部楼层
Post by leros_H
直接告诉他是使用的编译选项问题就行了吧!
这不能解决根本问题。要学驱动编程,只有老老实实地看LDD(linux device dirver).
不是有句话什么授鱼授渔的吗?

如果要学kernel 2.6 的驱动编程,看 edition3;
如果要学kernel 2.4 的驱动编程,看 edition2。
回复 支持 反对

使用道具 举报

发表于 2006-9-24 18:30:49 | 显示全部楼层
嗯, 读书是王道
回复 支持 反对

使用道具 举报

发表于 2006-9-27 10:11:24 | 显示全部楼层
不要直接用GCC,似乎需要很多系统Makefile的定义,所以用make找到源码树顶层的makefile吧。
回复 支持 反对

使用道具 举报

发表于 2006-9-28 21:26:28 | 显示全部楼层
编写驱动是要用kernel的编译系统的,坛子里有过帖子讨论,搜一下吧!
回复 支持 反对

使用道具 举报

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

本版积分规则

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