LinuxSir.cn,穿越时空的Linuxsir!

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

怎样才能加载成功啊?

[复制链接]
发表于 2004-4-7 20:22:22 | 显示全部楼层 |阅读模式
//It is copied from a book


#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif


#include </usr/src/linux-2.4.20-8/include/linux/kernel.h> /*We'ar doing kernel
work*/

#include </usr/src/linux-2.4.20-8/include/linux/module.h> /*Specifically a mod
ule*/



/*Deal with CONFIG_MODVERSIONS>*/



#if CONFIG_MODVERSIONS==1

#define <linux/modversions.h>

#endif



/*Initialize the module*/

int init_module()

{

        printk("Hello. World _ this is the kernel speaking\n");

       

        /* If we returned a non zero value, it means that

         * init_module failed and the kernel module can't be loaded*/



        return 0;

}



/*cleanup - undid whatever init_module did */

void cleanup_module()

{

        printk("Short is the file of the kernel module\n");

}

编译后加载,所有信息如下
[root@qg dd]# gcc -c helloword.c
In file included from /usr/src/linux-2.4.20-8/include/linux/module.h:25,
                 from helloword.c:11:
/usr/include/asm/atomic.h:40:2: warning: #warning Using kernel header in userl
and program. BAD!
[root@qg dd]# /sbin/insmod ./helloword.o
./helloword.o: kernel-module version mismatch
        ./helloword.o was compiled for kernel version 2.4.20
        while this kernel is version 2.4.20-8.

等待回答中...
多谢了 !
 楼主| 发表于 2004-4-7 22:53:05 | 显示全部楼层

on line waiting now!

on line waiting now!!
发表于 2004-4-8 01:25:58 | 显示全部楼层
你把/usr/include/linux连接到/usr/src/linux/include/linux试试
当然应该先建立一个/usr/src/linux的符号连接到你当前用的内核的源代码目录。
例子:
cd /usr/src
ln -s linux-2.4.20-8 linux
cd /usr/include
mv linux linux-bk
mv asm ams-bk
ln -s /usr/src/linux/include/linux
ln -s /usr/src/linux/include/asm
注意,这里的asm可能要你建立一个符号连接,应该在以上命令以前运行:
cd /usr/src/linux/include
ln -s asm-i386 asm

我对内核和驱动编程也不熟,仅供参考
发表于 2004-4-8 01:27:34 | 显示全部楼层
另外,你建好符号连接以后就可以直接用
#include <linux/kernel.h>
不用写那么长了
 楼主| 发表于 2004-4-8 21:09:19 | 显示全部楼层
非常感谢版主!
我去这就去试试.
 楼主| 发表于 2004-4-9 14:15:28 | 显示全部楼层

链接使我糊涂了...

本来编译没有错误的,现在编译也出现错误了

我的内核是2.4.20-8
我把/usr/src下的链接都删除了,想就用实际头文件的地址来include

这里出现的版本问题除了头文件的原因外,是不是还有编译器的问题,或是怎样选择编译器选项的问题?
 楼主| 发表于 2004-4-9 14:34:23 | 显示全部楼层
/usr/src 下有五个文件夹,分别是asm debug linux-2.4 linux-2.4.20-8
和 redhat, 其中链接asm指向/usr/src/linux/include/asm, linux和linux-2.4指向
同一目录的linux-2.4.20-8,我刚才删除了这几个链接,再次进入/usr/src 时,它们又出现了,一定是系统自动恢复的.
 楼主| 发表于 2004-4-9 14:39:58 | 显示全部楼层
本来编译成功后是这个信息:
[root@qg dd]# gcc -c helloword.c
In file included from /usr/src/linux-2.4.20-8/include/linux/module.h:25,
from helloword.c:11:
/usr/include/asm/atomic.h:40:2: warning: #warning Using kernel header in userl
and program. BAD!

现在出错了:
编译后加载,所有信息如下
[root@qg dd]# gcc -c helloword.c
In file included from /usr/src/linux-2.4.20-8/include/linux/module.h:25,
from helloword.c:11:
/usr/include/asm/atomic.h:40:2: warning: #warning Using kernel header in userl
and program. BAD!
 楼主| 发表于 2004-4-9 14:40:59 | 显示全部楼层

对不起,出错信息是:

[root@qg dd]# gcc -c helloword.c
In file included from /usr/include/linux/types.h:8,
                 from /usr/include/linux/kernel.h:13,
                 from helloword.c:10:
/usr/include/linux/posix_types.h:46:29: asm/posix_types.h: 没有那个文件或目录
In file included from /usr/include/linux/kernel.h:13,
                 from helloword.c:10:
/usr/include/linux/types.h:9:23: asm/types.h: 没有那个文件或目录
In file included from /usr/include/linux/kernel.h:13,
                 from helloword.c:10:
/usr/include/linux/types.h:14: parse error before "dev_t"
/usr/include/linux/types.h:15: parse error before "ino_t"
/usr/include/linux/types.h:16: parse error before "mode_t"
/usr/include/linux/types.h:17: parse error before "nlink_t"
/usr/include/linux/types.h:18: parse error before "off_t"
/usr/include/linux/types.h:19: parse error before "pid_t"
/usr/include/linux/types.h:20: parse error before "daddr_t"
/usr/include/linux/types.h:22: parse error before "suseconds_t"
/usr/include/linux/types.h:25: parse error before "uid_t"
/usr/include/linux/types.h:26: parse error before "gid_t"
/usr/include/linux/types.h:27: parse error before "uid16_t"
/usr/include/linux/types.h:28: parse error before "gid16_t"
/usr/include/linux/types.h:32: parse error before "old_uid_t"
/usr/include/linux/types.h:33: parse error before "old_gid_t"
/usr/include/linux/types.h:45: parse error before "loff_t"
/usr/include/linux/types.h:54: parse error before "size_t"
/usr/include/linux/types.h:59: parse error before "ssize_t"
/usr/include/linux/types.h:64: parse error before "ptrdiff_t"
/usr/include/linux/types.h:69: parse error before "time_t"
/usr/include/linux/types.h:74: parse error before "clock_t"
/usr/include/linux/types.h:79: parse error before "caddr_t"
/usr/include/linux/types.h:97: parse error before "u_int8_t"
/usr/include/linux/types.h:98: parse error before "int8_t"
/usr/include/linux/types.h:99: parse error before "u_int16_t"
/usr/include/linux/types.h:100: parse error before "int16_t"
/usr/include/linux/types.h:101: parse error before "u_int32_t"
/usr/include/linux/types.h:102: parse error before "int32_t"
/usr/include/linux/types.h:106: parse error before "uint8_t"
/usr/include/linux/types.h:107: parse error before "uint16_t"
/usr/include/linux/types.h:108: parse error before "uint32_t"
/usr/include/linux/types.h:111: parse error before "uint64_t"
/usr/include/linux/types.h:112: parse error before "u_int64_t"
/usr/include/linux/types.h:113: parse error before "int64_t"
/usr/include/linux/types.h:124: parse error before "__kernel_daddr_t"
/usr/include/linux/types.h:128: parse error before '}' token
In file included from helloword.c:10:
/usr/include/linux/kernel.h:15:27: asm/byteorder.h: 没有那个文件或目录
In file included from helloword.c:10:
/usr/include/linux/kernel.h:75: parse error before "size_t"
/usr/include/linux/kernel.h:77: parse error before "size_t"
/usr/include/linux/kernel.h:148:2: #error "lease fix asm/byteorder.h"
In file included from /usr/include/linux/list.h:6,
                 from /usr/include/linux/module.h:12,
                 from helloword.c:11:
/usr/include/linux/prefetch.h:13:27: asm/processor.h: 没有那个文件或目录
/usr/include/linux/prefetch.h:14:23: asm/cache.h: 没有那个文件或目录
In file included from helloword.c:11:
/usr/include/linux/module.h:25:24: asm/atomic.h: 没有那个文件或目录
In file included from helloword.c:11:
/usr/include/linux/module.h:62: parse error before "atomic_t"
/usr/include/linux/module.h:64: parse error before '}' token
/usr/include/linux/module.h:93: parse error before '}' token
helloword.c:16:9: macro names must be identifiers
[root@qg dd]#
 楼主| 发表于 2004-4-9 14:49:17 | 显示全部楼层
郁闷啊,似乎越来越糟糕!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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