我从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 example / simple 使
收到错误
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位系统并面临这个错误。我已经搜索了这些错误,但直到现在还没有任何帮助。
让我如何解决这个编译错误。
答案 0 :(得分:0)
如果要编译的目录中或包含内核源代码的目录中有空格,请尝试删除它们并再次make
。
如果您的编译目录中没有空格,并且仍然出现此错误,则内核编译可能会失败,因为其目录属于root
,并且您以非特权用户身份运行。尝试sudo make
。