LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1113|回复: 5

[菜鸟问]内核模块的编译错误

[复制链接]
发表于 2006-3-29 16:29:57 | 显示全部楼层 |阅读模式
/*  
*  hello-1.c - The simplest kernel module.
*/
#include <linux/module.h>        /* Needed by all modules */
#include <linux/kernel.h>        /* Needed for KERN_ALERT */

int init_module(void)
{
        printk("<1>Hello world 1.\n");

        /*
         * A non 0 return means init_module failed; module can't be loaded.
         */
        return 0;
}

void cleanup_module(void)
{
        printk("<1>Goodbye world 1.\n");
}

gcc -c hello.c时
错误如下:
In file included from /usr/include/linux/sched.h:16,
                 from /usr/include/linux/module.h:9,
                 from hello.c:4:
/usr/include/linux/signal.h:2:2: warning: #warning "You should include <signal.h>. This time I will do it for you."
In file included from /usr/include/linux/resource.h:4,
                 from /usr/include/linux/sched.h:79,
                 from /usr/include/linux/module.h:9,
                 from hello.c:4:
/usr/include/linux/time.h:9: 错误:‘struct timespec’ 重定义
/usr/include/linux/time.h:15: 错误:‘struct timeval’ 重定义
/usr/include/linux/time.h:20: 错误:‘struct timezone’ 重定义
/usr/include/linux/time.h:47: 错误:‘struct itimerval’ 重定义
In file included from hello.c:4:
/usr/include/linux/module.h:41: 错误:字段 ‘attr’ 的类型不完全
/usr/include/linux/module.h:49: 错误:字段 ‘kobj’ 的类型不完全
发表于 2006-3-29 17:02:52 | 显示全部楼层
用的什么版本的内核?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-3-29 17:19:11 | 显示全部楼层
2.6.12-10-386
不过在/usr/src下没有kernel-source 是不是要下载内核源码包 放到/usr/src下编译内核啊
请指教 谢谢
回复 支持 反对

使用道具 举报

发表于 2006-3-29 21:39:34 | 显示全部楼层
是啊!写驱动要有kernel-source。而且你的是2.4内核的写法,2.6已经有一些变化了。你程序的结构还有编译参数都不对!网上搜一下吧!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-3-29 23:38:39 | 显示全部楼层
Post by haohao_h
是啊!写驱动要有kernel-source。而且你的是2.4内核的写法,2.6已经有一些变化了。你程序的结构还有编译参数都不对!网上搜一下吧!
我在网上查了一下 重新改动了一下程序还是有错误
程序:
//hello.c
#include <linux/module.h>
#include <linux/config.h>
#include <linux/init.h>
static int hello_init(void)
{
        printk(KERN_ALERT "hello world\n");
        return 0;
       
}       

static void hello_exit(void)
{
        printk(KERN_ALERT "goodbye\n");
}

module_init(hello_init);
module_exit(hello_exit);

Makefile文件如下:
obj-m := hello.o
编译如下:
make -C ~/linux-2.6.12 M=`pwd` modules
(我下载的是linux-2.6.12-rc2.tar.gz 解压后吧名字改成了linux-2.6.12 我的系统是ubuntu)
错误如下:
make: Entering directory `/home/cooleagle/linux-2.6.12'
Makefile:487: .config: 没有那个文件或目录

  WARNING: Symbol version dump /home/cooleagle/linux-2.6.12/Module.symvers
           is missing; modules will have no dependencies and modversions.

  CC [M]  /home/cooleagle/program/kernel/hello.o
In file included from include/linux/module.h:9,
                 from /home/cooleagle/program/kernel/hello.c:1:
include/linux/config.h:4:28: error: linux/autoconf.h: 没有那个文件或目录
In file included from include/asm/thread_info.h:17,
                 from include/linux/thread_info.h:21,
                 from include/linux/spinlock.h:12,
                 from include/linux/capability.h:45,
                 from include/linux/sched.h:7,
                 from include/linux/module.h:10,
                 from /home/cooleagle/program/kernel/hello.c:1:
include/asm/processor.h:69: 错误:‘CONFIG_X86_L1_CACHE_SHIFT’ 未声明 (不在函数内)
include/asm/processor.h:69: 错误:要求的对齐边界不是常量
In file included from include/linux/module.h:23,
                 from /home/cooleagle/program/kernel/hello.c:1:
include/asm/module.h:58:2: error: #error unknown processor family
make[1]: *** [/home/cooleagle/program/kernel/hello.o] 错误 1
make: *** [_module_/home/cooleagle/program/kernel] 错误 2
make: Leaving directory `/home/cooleagle/linux-2.6.12'

请问是什么原因 谢谢
回复 支持 反对

使用道具 举报

发表于 2006-3-30 01:28:43 | 显示全部楼层
貌似你的内核并没有进行配置和编译. 这似乎是不可少的一步
回复 支持 反对

使用道具 举报

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

本版积分规则

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