当前位置: 技术问答>linux和unix
编译驱动模块出错,付上代码.请高手指点.
来源: 互联网 发布时间:2016-06-09
本文导语: 我从网上当了个驱动的小程序,修改了其中的错误之后想编译. 但是报错,错误是说在#include 中没有另一个头文件 我问了公司作底层驱动的同事,他说其实是我编译的命令不对,但我参照他的提示改了之后还是出错. 求具...
我从网上当了个驱动的小程序,修改了其中的错误之后想编译.
但是报错,错误是说在#include 中没有另一个头文件
我问了公司作底层驱动的同事,他说其实是我编译的命令不对,但我参照他的提示改了之后还是出错.
求具体的编译指令:
我的文件名就是test.c
--------------------------------------
代码
--------------------------------------
#define __NO_VERSION__
#include
#include
#include
#include
#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);
buf++;
}
return count;
}
static int write_test(struct inode *inode,
struct file *file,
const char *buf,
int count)
{
return count;
}
static int open_test(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 ; left--)
{
__put_user(1, buf);
buf++;
}
return count;
}
static int write_test(struct inode *inode,
struct file *file,
const char *buf,
int count)
{
return count;
}
static int open_test(struct inode *inode,
struct file *file )
{
return 0;
}
static void release_test(struct inode *inode,
struct file *file )
{
}
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
但是报错,错误是说在#include 中没有另一个头文件
我问了公司作底层驱动的同事,他说其实是我编译的命令不对,但我参照他的提示改了之后还是出错.
求具体的编译指令:
我的文件名就是test.c
--------------------------------------
代码
--------------------------------------
#define __NO_VERSION__
#include
#include
#include
#include
#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);
buf++;
}
return count;
}
static int write_test(struct inode *inode,
struct file *file,
const char *buf,
int count)
{
return count;
}
static int open_test(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 ; left--)
{
__put_user(1, buf);
buf++;
}
return count;
}
static int write_test(struct inode *inode,
struct file *file,
const char *buf,
int count)
{
return count;
}
static int open_test(struct inode *inode,
struct file *file )
{
return 0;
}
static void release_test(struct inode *inode,
struct file *file )
{
}
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