当前位置: 技术问答>linux和unix
liunx 驱动测试小程序不能编译,求指导
来源: 互联网 发布时间:2017-02-14
本文导语: 一下是我的一个linux驱动的测试小程序,但是编译时老是报:fatal error: linux/module.h: No such file or directory这样的错误,我用-I指令将其路径加了进去还是不行,以下是源码:我看网上说着要用makefile编译,我是菜鸟...
一下是我的一个linux驱动的测试小程序,但是编译时老是报:fatal error: linux/module.h: No such file or directory这样的错误,我用-I指令将其路径加了进去还是不行,以下是源码:我看网上说着要用makefile编译,我是菜鸟写了一个不好使,忘大神能指导一下
#define __NO_VERSION__
#include
#include
char kernel_version [] = UTS_RELEASE;
#include #include #include #include #include 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
#define __NO_VERSION__
#include
#include
char kernel_version [] = UTS_RELEASE;
#include #include #include #include #include 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