Ramy Sameh Ramy Sameh - 1 year ago 206
Linux Question

Error when compiling Linux kernel 3.2 for ARM

I am following this tutorial to compile Linux kernel 3.2 for ARM and emulate with QEMU:


I am following the below steps:

  1. wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.2.tar.bz2

  2. tar xjf linux-3.2.tar.bz2

  3. export ARCH=arm

  4. export CROSS_COMPILE=arm-linux-gnueabi-

  5. cd linux-3.2

  6. make vexpress_defconfig

  7. make all

  8. cd ..

  9. arm-linux-gnueabi-gcc -static init.c -o init

  10. echo init|cpio -o --format=newc > initramfs

  11. qemu-system-arm -M vexpress-a9 -kernel linux-3.2/arch/arm/boot/zImage -initrd initramfs -serial stdio -append "console=tty1"

My problem is when I try step 7 (make all), this problem happens:

include/linux/compiler-gcc.h:94:30: fatal error: linux/compiler-gcc5.h: No such file or directory
compilation terminated.
/home/ramy/QEMU_Learn/kernel/linux-3.2/./Kbuild:35: recipe for target 'kernel/bounds.s' failed
make[1]: *** [kernel/bounds.s] Error 1
Makefile:985: recipe for target 'prepare0' failed

I am working Ubuntu operating system, and I am using Linaro tool chain to compile the kernel.

I have also checked the PATH variable and here is the result:

$ printenv | grep PATH


Answer Source

Your kernel version (3.2.0) is too old and not compatible with used gcc (gcc-5). You may use gcc-4 to compile kernel, or use newer kernel version.

Your kernel has special include in linux/compiler-gcc.h header http://lxr.free-electrons.com/source/include/linux/compiler-gcc.h?v=3.2#L91

 91 #define __gcc_header(x) #x
 92 #define _gcc_header(x) __gcc_header(linux/compiler-gcc##x.h)
 93 #define gcc_header(x) _gcc_header(x)
 94 #include gcc_header(__GNUC__)

It will include different files for different gcc versions (GNUC is major version of gcc). It supports gcc-3 and gcc-4, but not gcc-5:


C file  compiler-gcc.h  3705 bytes
C file  compiler-gcc3.h 631 bytes
C file  compiler-gcc4.h 2073 bytes
C file  compiler-intel.h    746 bytes
C file  compiler.h  8628 bytes

You may try to rewrite compiler-gcc4.h to compiler-gcc5.h, but you should understand how to do this. You may not just copy gcc4 to gcc5, there will incorrect macro.

The compiler-gcc5.h was added only to linux kernel version 3.18: http://lxr.free-electrons.com/source/include/linux/compiler-gcc5.h?v=3.18 (not in 3.17 http://lxr.free-electrons.com/source/include/linux/compiler-gcc5.h?v=3.17)

Older linaro compiler (before gcc-5) is https://releases.linaro.org/components/toolchain/binaries/4.9-2016.02/

And according to JJ Hakala comment, there is the compiler-gcc5 header in last version of 3.2.* kernel, the 3.2.81: https://www.kernel.org/pub/linux/kernel/v3.0/linux-3.2.81.tar.gz - just change wget command and tar xjf to this version and retry.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download