解决编译/home/module/hello.c:1: 错误:代码模式‘kernel’在 32 位模式下不受支持问题

来源:互联网 发布:视频模板制作软件 编辑:程序博客网 时间:2024/06/05 19:34

当时在自己的开发板GT2440上移植u-boot,linux,根文件系统时,一切移植好之后,想测试下insmod命令,于是写了个hello简单的模块测试程序,但是编译时遇到的一个奇怪的问题:

make之后总是出错:
/home/module/hello.c:1: 错误:代码模式‘kernel’在 32 位模式下不受支持
/home/module/hello.c:1: 对不起,尚未实现:未编译入对 64 位模式的支持
make[2]: *** [/home/module/hello.o] 错误 1
make[1]: *** [_module_/home/module] 错误 2

下面是makefile

KERNELDIR= /home/GT2440/rootfs/lib/modules/2.6.30/build/

PWD := $(shell pwd)

obj-m := hello.o

modules:                             
        $(MAKE) -C $(KERNELDIR) M=$(PWD) modules

modules_install:
        cp hello.ko $(INSTALLDIR)

clean:
        rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions

.PHONY: modules modules_install clean


初学者,上面的makefile是上网找了很久,各种版本的杂糅版.....结果不对,make之后
提示
ake -C /GT2440/linux/linux2.6.30 M=/home/GT2440/test modules
make[1]: Entering directory `/GT2440/linux/linux-2.6.30'
  CC [M]  /home/GT2440/test/hello.o
cc1: error: invalid option `64'
cc1: error: invalid option `no-red-zone'
cc1: error: invalid option `cmodel=kernel'
cc1: error: invalid option `no-sse'
cc1: error: invalid option `no-mmx'
cc1: error: invalid option `no-sse2'
cc1: error: invalid option `no-3dnow'
cc1: error: invalid option `accumulate-outgoing-args'
make[2]: *** [/home/GT2440/test/hello.o] 错误 1
make[1]: *** [_module_/home/GT2440/] 错误 2
make[1]: Leaving directory `/GT2440/linux/linux-2.6.30'
根据自己分析,应该是不能识别CROSS_COMPILE,于是在linux内核目录下修改Makefile文件,修改如下:

ARCH=arm

CROSS_COMPILE=arm-linux-

在编译下hello.c模块,通过。