首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

liunx 驱动测试小程序不能编译,求指导,该怎么解决

2012-04-13 
liunx 驱动测试小程序不能编译,求指导一下是我的一个linux驱动的测试小程序,但是编译时老是报:fatal error

liunx 驱动测试小程序不能编译,求指导
一下是我的一个linux驱动的测试小程序,但是编译时老是报:fatal error: linux/module.h: No such file or directory这样的错误,我用-I指令将其路径加了进去还是不行,以下是源码:我看网上说着要用makefile编译,我是菜鸟写了一个不好使,忘大神能指导一下

#define __NO_VERSION__ 
#include <linux/version.h> 
#include <linux/module.h> 

char kernel_version [] = UTS_RELEASE;
#include <linux/types.h> #include <linux/fs.h> #include <linux/mm.h> #include <linux/errno.h> #include <asm/segment.h> unsigned int test_major = 0; 
static int read_test(struct inode *node,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 int open_tibet(struct inode *inode,struct file *file ) 
{
MOD_INC_USE_COUNT; 
return 0; 


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, /* test_readdir */
NULL, 
NULL, /* test_ioctl */ 
NULL, /* test_mmap */
open_test, 
release_test, 
NULL, /* test_fsync */ 
NULL, /* test_fasync */
/* nothing more, fill with NULLs */ 
};

int init_module(void)

int result; 
result = register_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; /* dynamic */ 
return 0; 
}  

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

[解决办法]
可能你的Makefile有问题

Assembly code
obj-m := test.oKDIR ?= /lib/modules/$(shell uname -r)/buildPWD := $(shell pwd)EXTRA_CFLAGS += -O2 -Wallall: module cleanupmodule:    $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modulescleanup:    rm -f *.o .*.cmd *.mod.c; rm -rf .tmp_versionsclean: cleanup    rm -f *.ko test
[解决办法]
当然了,还需要上面仁兄提供的 makefile没问题。

热点排行