chensuoqian
驱动牛犊
驱动牛犊
  • 注册日期2003-02-25
  • 最后登录2003-06-04
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1290回复:7

关于编译的问题!!!!

楼主#
更多 发布于:2003-03-11 16:46
我是个菜鸟!!!!问一个问题,我在看<<LINUX DEVICE DRIVERS>>这本书时,编译里面的例子通不过,为什么?????
比如最简单的:

define module
#include <linux/module.h>

int init_module(void)  
       { printk(\"<1>hello,world\\n\");return 0;}
void  cleanup_module  
       { printk(\"<1>goodbye cruel world\\n\");}
hometown
驱动大牛
驱动大牛
  • 注册日期2002-10-24
  • 最后登录2004-05-21
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2003-03-11 19:57
我是个菜鸟!!!!问一个问题,我在看<<LINUX DEVICE DRIVERS>>这本书时,编译里面的例子通不过,为什么?????
比如最简单的:

define module
#include <linux/module.h>

int init_module(void)  
       { printk(\"<1>hello,world\\n\");return 0;}
void  cleanup_module  
       { printk(\"<1>goodbye cruel world\\n\");}


你写错了!
第一句应该为:
#define  MODULE   <-----------是大写, 而且不要掉了#
How fair and how pleasant art thou, O love, for delights!This thy stature is like to a palm tree, and thy breasts to clusters of grapes.I said, I will go up to the palm tree, I will take hold of the boughs thereof: now also thy breasts shall be as clusters of the vine, and the smell of thy nose like apples;And the roof of thy mouth like the best wine for my beloved, that goeth down sweetly, causing the lips of those that are asleep to speak.
i++
i++
驱动牛犊
驱动牛犊
  • 注册日期2002-10-24
  • 最后登录2003-03-13
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2003-03-11 21:22
还有一定要注意
gcc默认的include目录和编译模块的include目录不一样,前一个是
/usr/include ,而后一个是/usr/src/linux-2.x.x/include
所以编译的时候一定要在gcc中加入一个编译选项-I/usr/src/linux-2.x.x/include
hometown
驱动大牛
驱动大牛
  • 注册日期2002-10-24
  • 最后登录2004-05-21
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地板#
发布于:2003-03-12 22:08
还有一定要注意
gcc默认的include目录和编译模块的include目录不一样,前一个是
/usr/include ,而后一个是/usr/src/linux-2.x.x/include
所以编译的时候一定要在gcc中加入一个编译选项-I/usr/src/linux-2.x.x/include
通常是/usr/src/LINUX-VERSION(linux)/include拷贝到/usr/include下, 这不是问题。 通常做驱动的时候要加上选项-O8(大于3就可) 还有为了移植加-DLINUX, 另一个选项是-D__KERENLD__; 为了获得最大的报警, 可加上-Wall。 基本上就是这些选项了 :D :D
How fair and how pleasant art thou, O love, for delights!This thy stature is like to a palm tree, and thy breasts to clusters of grapes.I said, I will go up to the palm tree, I will take hold of the boughs thereof: now also thy breasts shall be as clusters of the vine, and the smell of thy nose like apples;And the roof of thy mouth like the best wine for my beloved, that goeth down sweetly, causing the lips of those that are asleep to speak.
chensuoqian
驱动牛犊
驱动牛犊
  • 注册日期2003-02-25
  • 最后登录2003-06-04
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2003-03-15 10:23
我的内核版本是2.4.14-18的redhat linux 8.0,照你的办法还是通不过!!!!
hometown
驱动大牛
驱动大牛
  • 注册日期2002-10-24
  • 最后登录2004-05-21
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
5楼#
发布于:2003-03-18 12:52
我的内核版本是2.4.14-18的redhat linux 8.0,照你的办法还是通不过!!!!
上面的例子在2。0和2。2的可通过的, 2。4的应该写法有些不同, 不过思想是一样的
How fair and how pleasant art thou, O love, for delights!This thy stature is like to a palm tree, and thy breasts to clusters of grapes.I said, I will go up to the palm tree, I will take hold of the boughs thereof: now also thy breasts shall be as clusters of the vine, and the smell of thy nose like apples;And the roof of thy mouth like the best wine for my beloved, that goeth down sweetly, causing the lips of those that are asleep to speak.
Pharos
驱动牛犊
驱动牛犊
  • 注册日期2001-08-13
  • 最后登录2005-02-28
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
6楼#
发布于:2003-03-18 21:48
你写的是一个简单的驱动程序,代码有一点小问题,不过不会是编译不通过的理由,我试过了,你的代码可以编译过去,而且还可以用insmod/rmmod命令安装/卸载,工作正常。
没有我,你怎么办,你的泪水谁为你擦干; 谁为你打伞,安慰你心寒,失眠的夜你最怕孤单。
heehaw
驱动小牛
驱动小牛
  • 注册日期2003-03-20
  • 最后登录2005-04-25
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
7楼#
发布于:2003-03-20 14:35
我也刚开始看这边书,
这个程序我调通了,就是在编译的时候指定使用src里面的头文件就可以了,insmod和rmmod后,信息会打印在
在/var/log/messages中
gcc -DMODULE -D__KERNEL__ -I/usr/src/linux-2.4/include -c hello.c

应该没有问题 :)
我热爱生命,但面对现实的社会经常感到无奈,所以只有嘿嘿傻笑 我迷恋科技,但飞速发展的世界使我眼花缭乱,所以必须埋头苦练
游客

返回顶部