免费注册 查看新帖 |

Chinaunix

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

[驱动] 设备驱动程序开发的编译问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-10-12 20:18 |只看该作者 |倒序浏览
先谢谢大家的帮忙了啊

/*
*        Hello world module.
*/
//#include <linux/init.h>

#include <linux/module.h>

#if defined(CONFIG_SMP)
#define __SMP__
#endif

#if defined(CONFIG_MODVERSIONS)
#define MODVERSIONS
#include <linux/modversions.h>
#endif

#include <linux/kernel.h>

static __init int init_module(void)
{
        printk(KERN_DEBUG "Hello, kernel!\n");
        return 0;
}

static __exit void cleanup_module(void)
{
        printk(KERN_DEBUG "Good-bye, kernel!\n");
}

这个是Linux程序设计上设备驱动程序开发的代码
我是在虚拟机上安装的CentOS-4.6

我按照书上的编译命令
gcc -D__KERNEL__-DMODULE -DMODVERSIONS -I /user/src/kernels/2.6.9-67.EL-smp-i686/include -Wall -O2  -o hello -c hello.c
但是出现了 <command line>:1:11: warning: ISO C requires whitespace after the macro name
In file included from /usr/include/linux/module.h:10,
                 from hello.c:6:
/usr/include/linux/config.h:5:2: #error Incorrectly using glibc headers for a kernel module
hello.c:19: error: syntax error before "int"
hello.c: In function `init_module':
hello.c:21: warning: implicit declaration of function `printk'
hello.c:21: error: `KERN_DEBUG' undeclared (first use in this function)
hello.c:21: error: (Each undeclared identifier is reported only once
hello.c:21: error: for each function it appears in.)
hello.c:21: error: syntax error before string constant
hello.c: At top level:
hello.c:25: error: syntax error before "void"
hello.c: In function `cleanup_module':
hello.c:27: error: `KERN_DEBUG' undeclared (first use in this function)
hello.c:27: error: syntax error before string constant
[yangww_cs@localhost driver]$

请问这个问题怎么解决啊?
很着急啊~
已经试了两天了,但是还是这样~
谢谢大家帮忙啊

论坛徽章:
0
2 [报告]
发表于 2010-10-12 20:20 |只看该作者
我的QQ是347073999
大家可以加Q解决~
远程协作~
麻烦了啊~
实在头大啊

论坛徽章:
0
3 [报告]
发表于 2010-10-12 22:47 |只看该作者
把相关头文件include进来吧,为了省麻烦,我一般
  1. #include <linux/module.h>
  2. #include <linux/types.h>
  3. #include <linux/fs.h>
  4. #include <linux/errno.h>
  5. #include <linux/mm.h>
  6. #include <linux/sched.h>
  7. #include <linux/init.h>
  8. #include <linux/cdev.h>
  9. #include <linux/poll.h>
  10. #include <asm/io.h>
  11. #include <asm/system.h>
  12. #include <asm/uaccess.h>
复制代码
而且这个不是2.6内核的写法?我记得是
  1. int drv_init()
  2. {

  3. }

  4. void drv_exit()
  5. {
  6.    
  7. }

  8. module_init(drv_init);
  9. module_exit(drv_exit);
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP