【发布时间】:2016-04-28 06:06:22
【问题描述】:
我从http://examples.oreilly.com/9780596005900/下载了一些非常有名的linux内核示例模块
并尝试在我的系统上编译。
我的系统信息:
cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04.5 LTS"
uname -a
Linux user 3.13.0-32-generic #57~precise1-Ubuntu SMP Tue Jul 15 03:51:20 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
cd 示例/简单 制作
出现错误
make -C /lib/modules/3.13.0-32-generic/build M=/home/user/projects/self/examples/simple LDDINCDIR=/home/user/projects/self/examples/simple/../include modules
make[1]: Entering directory `/usr/src/linux-headers-3.13.0-32-generic'
/usr/src/linux-headers-3.13.0-32-generic/arch/x86/Makefile:98: stack protector enabled but no compiler support
/usr/src/linux-headers-3.13.0-32-generic/arch/x86/Makefile:113: CONFIG_X86_X32 enabled but no binutils support
scripts/Makefile.build:49: *** CFLAGS was changed in "/home/user/projects/self/examples/simple/Makefile". Fix it to use ccflags-y. Stop.
make[1]: *** [_module_/home/user/projects/self/examples/simple] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.13.0-32-generic'
make: *** [default] Error 2
我知道现在内核构建系统不允许在内核之外更改 CFLAGS,所以以这种方式更改 Makefile
-CFLAGS += $(DEBFLAGS) -I$(LDDINCDIR)
+ccflags-y += $(DEBFLAGS) -I$(LDDINCDIR)
现在再次制作并获取以下错误消息
make -C /lib/modules/3.13.0-32-generic/build M=/home/user/projects/self/examples/simple LDDINCDIR=/home/user/projects/self/examples/simple/../include modules
make[1]: Entering directory `/usr/src/linux-headers-3.13.0-32-generic'
/usr/src/linux-headers-3.13.0-32-generic/arch/x86/Makefile:98: stack protector enabled but no compiler support
/usr/src/linux-headers-3.13.0-32-generic/arch/x86/Makefile:113: CONFIG_X86_X32 enabled but no binutils support
CC [M] /home/user/projects/self/examples/simple/simple.o
cc1: error: unrecognized command line option "-m64"
cc1: error: unrecognized command line option "-mno-mmx"
cc1: error: unrecognized command line option "-mno-sse"
cc1: error: unrecognized command line option "-mno-red-zone"
cc1: error: unrecognized command line option "-mcmodel=kernel"
cc1: error: unrecognized command line option "-maccumulate-outgoing-args"
make[2]: *** [/home/user/projects/self/examples/simple/simple.o] Error 1
make[1]: *** [_module_/home/user/projects/self/examples/simple] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.13.0-32-generic'
make: *** [default] Error 2
之前我已经在我的 32 位系统上成功编译了这些示例,但现在我转移到 64 位系统并面临这个错误。我用谷歌搜索了这些错误,但到目前为止还没有任何帮助。
让我如何解决这个编译错误。
【问题讨论】:
-
您正在使用不支持的编译器来编译内核,请尝试切换支持的编译器,例如 gcc。
-
您似乎使用了错误的编译器版本。也许 64 位版本编译 32 位 sdk?
-
谢谢大家添加 CC = gcc 解决了上述问题,但仍然遇到与 linux/config.h 文件相关的问题,因为它已从最新内核源中删除,并且此模块适用于 2.6 内核
-
您应该删除对该标头的所有引用。那么它应该可以工作了。
标签: c linux linux-kernel embedded linux-device-driver