发新话题
打印

编译模块时出现的错误

编译模块时出现的错误

模块源文件(hello.c)代码:
#include <linux/module.h>
#include <linux/kernel.h>

int init_module(void){
        printk("<1>hello word!\n");
        return 0;
}

void cleanup_module(void){
       
}

Makefile:
TARGET  := hello
WARN    := -W -Wall -Wstrict-prototypes -Wmissing-prototypes
INCLUDE := -isystem /lib/modules/2.6.22.6-1/build/include/
CFLAGS  := -O2 -DMODULE -D__KERNEL__ ${WARN} ${INCLUDE}
CC      := gcc
        
${TARGET}.o: ${TARGET}.c

.PHONY: clean

make时的错误提示:
gcc -O2 -DMODULE -D__KERNEL__ -W -Wall -Wstrict-prototypes -Wmissing-prototypes -isystem /lib/modules/2.6.22.6-1/build/include/   -c -o hello.o hello.c
In file included from /lib/modules/2.6.22.6-1/build/include/asm/thread_info.h:16,
                 from /lib/modules/2.6.22.6-1/build/include/linux/thread_info.h:21,
                 from /lib/modules/2.6.22.6-1/build/include/linux/preempt.h:9,
                 from /lib/modules/2.6.22.6-1/build/include/linux/spinlock.h:49,
                 from /lib/modules/2.6.22.6-1/build/include/linux/module.h:9,
                 from hello.c:1:
/lib/modules/2.6.22.6-1/build/include/asm/processor.h:83: error: ‘CONFIG_X86_L1_CACHE_SHIFT’ undeclared here (not in a function)
/lib/modules/2.6.22.6-1/build/include/asm/processor.h:83: error: requested alignment is not a constant
In file included from /lib/modules/2.6.22.6-1/build/include/linux/module.h:21,
                 from hello.c:1:
/lib/modules/2.6.22.6-1/build/include/asm/module.h:64:2: error: #error unknown processor family

能帮帮我吗(linux为2.6.22.6-1)

[ 本帖最后由 linkstack 于 2008-3-17 11:27 编辑 ]      

TOP

你的模块是按2.4的规则,在2.6里面不是这么写的
去百度一下“开发简单的 Linux2.6 内核模块”
你会有收获的。      
1,本人乃Linux伊甸园“Linux内核学习”,“红旗等发行版”版主,请大家捧场。
2,红旗Linux在设备驱动,系统设置,中文美化,易用性方面做得非常好,建议大家使用。
3,本人是红旗Linux的粉丝,不是枪手。

TOP

感谢版主!非常感谢!
改正后的Makefile:
obj-m += hello.o

命令:
make -C /usr/src/linux-`uname -r` SUBDIRS=$PWD modules

就可以正常地编译模块了
再次感谢版主!      

TOP

发新话题