QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2383|回复: 5

简单驱动编译问题请教

[复制链接]
发表于 2008-12-15 13:29:41 | 显示全部楼层 |阅读模式
我在编译下面HELLO时,能够通过,且可正常装载。
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void)
{
        printk("Hello, iceboy !\n");
        return 0;
}

static void hello_exit(void)
{
        printk("Goodbye, iceboy !\n");
}

module_init(hello_init);
module_exit(hello_exit);


但是下面的简单字符驱动,却编译不过。如下:
#define _KERNEL_
#define MODULE

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>

ssize_t test_read(struct file * fp, char *cp , size_t size, loff_t * off)
{
return 0;
}

struct file_operations test = {
read:test_read,
};

int init_module(void)
{
return 0;
}

void cleanup_module(void)
{
}

报的错误是:
xtest.C:23: variable `file_operations test' has initializer but incomplete type
xtest.C:23: storage size of `test' isn't known

我的内核是2.4的,编译环境:
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)

大侠们,多多指教啊!

还有个问题,加上_kernel_ 就上面一个错,但改成__kernel__时,就一大推头文件包含错误。
 楼主| 发表于 2008-12-17 15:44:08 | 显示全部楼层
哎,没人愿意帮忙吗 ?
回复

使用道具 举报

发表于 2008-12-17 17:06:32 | 显示全部楼层
帮不了你啊……
第一个问题貌似是变量初始化不对,可能是没有初始化正确。
第二个应该就是纯粹的语法错了。
回复

使用道具 举报

 楼主| 发表于 2008-12-18 15:41:32 | 显示全部楼层
感谢楼上的答案!
继续努力解决中。。。
回复

使用道具 举报

 楼主| 发表于 2008-12-22 10:29:02 | 显示全部楼层
已解决。
后缀.C改为.c即可!
回复

使用道具 举报

发表于 2008-12-22 11:14:01 | 显示全部楼层
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-4-20 02:40 , Processed in 0.101304 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表