求助:第一次写驱动

编译打包和其他
回复
xmuch
帖子: 2
注册时间: 2008-04-19 14:35

求助:第一次写驱动

#1

帖子 xmuch » 2008-04-19 16:59

#gcc -O2 -DMODULE -D__KERNEL__ -c first.c

linux/module.h:No such file or director
linux/mm.h:No such file or directory
linux/error.h:No such file or directory
linux/config.h:No such file or directory
asm/segment.h:No such file or directory
为什么会出现这样的错误?
不是说建立内核树就可以了吗
我是第一次开始学写驱动,请大家帮帮忙,多多赐教阿
还有,我试着按照 linuxdevicedriver3 里说的写的一个驱动

#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/version.h>
#include<linux/types.h>
#include<linux/fs.h>
#include<linux/mm.h>
#include<linux/error.h>
#include<linux/config.h>
#include<asm/segment.h>
unsigned int test_major = 0;
static int read_test(struct inode *inode,struct file *file,char *buf,int count){
int left;
if (verify_area(VERIFY_WRITE,buf,count) == -EFAULT)
return -EFAULT;
for (left = count; left > 0 ; left--){
__put_user(1,buf,1);
buf++;
}
return count;
}

static int write_test(struct inode *inode,struct file *file,const char *buf, int count){
return count;
}

static void release_test(struct inode *inode,struct file *file,){
MOD_DEC_USE_COUNT;
}

struct file_operations test_fops = {
NULL,
read_test,
write_test,
NULL,
NULL,
NULL,
NULL,
open_test,
release_test,
NULL,
};

int init_module(void){
int result;
result = regster_chrdev(0,"test",&test_fops);
if(result < 0){
printk(KERN_INFO "test:can't get major number!\n");
return result;
}
if(test_major == 0)test_major = result;
return 0;
}

void cleanup_module(void){
unregister_chrdev(test_major,"test");
}

只要这样一个.c文件就可以了吗?

大家帮帮忙呵
alertsniper
帖子: 296
注册时间: 2007-09-22 21:49
联系:

#2

帖子 alertsniper » 2008-04-22 12:26

inux/module.h:No such file or director
linux/mm.h:No such file or directory
linux/error.h:No such file or directory
linux/config.h:No such file or directory
asm/segment.h:No such file or directory
===============================
LZ!这些头文件呢????没有他怎么编译???
PS:我也不懂怎么写驱动....
langgui
帖子: 7
注册时间: 2008-04-24 10:10
联系:

#3

帖子 langgui » 2008-04-28 8:56

找不到相应的头文件。
头像
天浩
帖子: 146
注册时间: 2007-04-14 0:41
来自: 武汉
联系:

#4

帖子 天浩 » 2008-05-03 22:12

ubuntu的默认安装没有建立内核树,所以要自己编译内核
参考:viewtopic.php?t=109762&postdays=0&postorder=asc&start=0
头像
dwl301
帖子: 1131
注册时间: 2007-04-14 11:17

#5

帖子 dwl301 » 2008-05-18 21:53

关注中·················
头像
sonixrp
帖子: 505
注册时间: 2007-03-28 12:39

#6

帖子 sonixrp » 2008-05-18 21:58

支持,虽然我完全看不懂C不过真的想好好学 学 呢 ~
目前研究自编译内核,有兴趣的朋友一起来吧~
imcg
帖子: 3
注册时间: 2010-03-28 13:59

Re: 求助:第一次写驱动

#7

帖子 imcg » 2010-03-28 14:00

天浩给的网站酷!谢了! :em11
回复