|
我使用的是Fedora9虚拟机,安装的内核是kernel-2.6.25-14.fc9.src.rpm,
源码目录是/usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686,我是在make install结束后进行下面操作的
[root@localhost HelloWorld]# ls
hello.c makefile
接下来就是模块编译时候遇到的问题
[root@localhost HelloWorld]# gcc -c -I/usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/ hello.c
In file included from /usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/linux/prefetch.h:14,
from /usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/linux/list.h:8,
from /usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/linux/module.h:9,
from hello.c:9:
/usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/asm/processor.h:102: 错误:‘CONFIG_X86_L1_CACHE_SHIFT’ 未声明 (不在函数内)
/usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/asm/processor.h:102: 错误:要求的对齐边界不是常量
/usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/asm/processor.h: In function ‘load_cr3’:
/usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/asm/processor.h:162: 错误:‘CONFIG_PAGE_OFFSETUL’ 未声明 (在此函数内第一次使用)
/usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/asm/processor.h:162: 错误:(即使在一个函数内多次出现,每个未声明的标识符在其
/usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/asm/processor.h:162: 错误:所在的函数内只报告一次。)
/usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/asm/processor.h: 在顶层:
/usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/asm/processor.h:201: 错误:要求的对齐边界不是常量
In file included from /usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/asm/thread_info.h:4,
from /usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/linux/thread_info.h:35,
from /usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/linux/preempt.h:9,
from /usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/linux/spinlock.h:49,
from /usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/linux/seqlock.h:29,
from /usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/linux/time.h:8,
from /usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/linux/stat.h:60,
from /usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/linux/module.h:10,
from hello.c:9:
/usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/asm/thread_info_64.h: In function ‘current_thread_info’:
/usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/asm/thread_info_64.h:66: 错误:‘THREAD_SIZE’ 未声明 (在此函数内第一次使用)
/usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/asm/thread_info_64.h: In function ‘stack_thread_info’:
/usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/asm/thread_info_64.h:74: 错误:‘THREAD_SIZE’ 未声明 (在此函数内第一次使用)
In file included from /usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/linux/elf.h:7,
from /usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/linux/module.h:14,
from hello.c:9:
/usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/asm/elf.h: In function ‘elf_common_init’:
/usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/asm/elf.h:165: 错误:‘struct pt_regs’ 没有名为 ‘r8’ 的成员
/usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/asm/elf.h:165: 错误:‘struct pt_regs’ 没有名为 ‘r9’ 的成员
/usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/asm/elf.h:165: 错误:‘struct pt_regs’ 没有名为 ‘r10’ 的成员
/usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/asm/elf.h:165: 错误:‘struct pt_regs’ 没有名为 ‘r11’ 的成员
/usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/asm/elf.h:166: 错误:‘struct pt_regs’ 没有名为 ‘r12’ 的成员
/usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/asm/elf.h:166: 错误:‘struct pt_regs’ 没有名为 ‘r13’ 的成员
/usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/asm/elf.h:166: 错误:‘struct pt_regs’ 没有名为 ‘r14’ 的成员
/usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/asm/elf.h:166: 错误:‘struct pt_regs’ 没有名为 ‘r15’ 的成员
在包含自 /usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/linux/module.h:21 的文件中,
从 hello.c:9:
/usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/include/asm/module.h:70:2: 错误:#error unknown processor family
hello.c: 在顶层:
hello.c:16: 错误:expected ‘)’ before string constant
下面这个是我的hello.c
[root@localhost HelloWorld]# cat hello.c
#ifndef __KERNEL__
# define __KERNEL__
#endif
#ifndef MODULE
# define MODULE
#endif
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
MODULE_LICENSE("GPL");
static int year=2007;
MODULE_PARM(year,"i");
int hello_init()
{
printk(KERN_WARNING"Hello World %d!\n",year);
return 0;
}
void hello_exit()
{
printk("Hello Exit!\n");
}
module_init(hello_init);
module_exit(hello_exit);
|
|