boblai
驱动牛犊
驱动牛犊
  • 注册日期2004-02-17
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1143回复:3

请问各位大虾,这编译错误是版本的原因吗?

楼主#
更多 发布于:2004-04-26 12:31
请问各位大虾,这编译错误是版本的原因吗?
编译命令该如何写?请各位大虾告诉小弟是什么原因,谢了!


我写了一个很简单的linux驱动,程序如下:
#define MODULE
#define __KERNEL__
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/fs.h>
#include <linux/malloc.h>
#include <asm/unistd.h>
#include <sys/syscall.h>
#include <asm/fcntl.h>
#include <asm/errno.h>
#include <linux/types.h>
#include <linux/dirent.h>

static int driver_open(struct inode *i, struct file *f)
{
printk(\"<1>Open Function\\n\");
return 0;
}

static struct file_operations fops = {
NULL, /* owner */
NULL, /*lseek*/
NULL, /*read*/
NULL, /*write*/
NULL, /*readdir*/
NULL, /*poll*/
NULL, /*ioctl*/
NULL, /*mmap*/
driver_open, /*open, take a look at my dummy open function*/
NULL, /*release*/
NULL, /*fsync...*/
NULL,
NULL,
NULL,
NULL,
NULL
};
int init_module(void)
{
if(register_chrdev(30, \"mydriver\", &fops)) return -EIO;
return 0;
}
void cleanup_module(void)
{
/*unregister our driver*/
unregister_chrdev(30, \"mydriver\");
}  
 
 

然后用gcc -O2 -DMODULE -D _KERNEL_ -c test.c时会出现如下错误:
/usr/include/linux/module.h:60:parser error before \'atomic_t\'
/usr/include/linux/module.h:60:warning....
/usr/include/linux/module.h:60:warning....
/usr/include/linux/module.h:62:parser error before \'}\'
/usr/include/linux/module.h:91:parser error before \'}\'






 
我穿着开档裤坐在石头上,石头很烫但是很舒服,地上还有一条蚯蚓。。。。。。
Forest_Leo
驱动牛犊
驱动牛犊
  • 注册日期2004-02-26
  • 最后登录2004-11-15
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2004-04-26 15:00
用  -I 指定内核库文件所在目录,不要用普通应用程序编译时的库文件目录
unix1998
驱动老牛
驱动老牛
  • 注册日期2002-05-08
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分6分
  • 威望2点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2004-04-27 07:13
驱动没错,看makefile
boblai
驱动牛犊
驱动牛犊
  • 注册日期2004-02-17
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地板#
发布于:2004-04-27 09:42
谢谢各位大虾!

引用:
   用 -I 指定内核库文件所在目录,不要用普通应用程序编译时的库文件目录

   然后用gcc -O2 -DMODULE -D _KERNEL_ -c test.c \\I /usr/src/linux-2.4/include进行编译,好象没错误,有一些warning,请问各位大虾为何在源文件当地看不到test.o文件
 
我穿着开档裤坐在石头上,石头很烫但是很舒服,地上还有一条蚯蚓。。。。。。
游客

返回顶部