'elf.h' file not found error when compiling Android kernel for Nexus 7 on Mac OS X

Derek Gogol picture Derek Gogol · Oct 17, 2013 · Viewed 8.3k times · Source

When compiling Android kernel for Nexus 7 on Mountain Lion 10.8.4 I ran into fatal error: 'elf.h' file not found issue:

/Volumes/Android/WORKING_DIRECTORY/device/asus/grouper/tegra/
[derek@retina-mbp]$ make
scripts/kconfig/conf --silentoldconfig Kconfig
  CHK     include/linux/version.h
  UPD     include/linux/version.h
  CHK     include/generated/utsrelease.h
  UPD     include/generated/utsrelease.h
  Generating include/generated/mach-types.h
  CC      kernel/bounds.s
  GEN     include/generated/bounds.h
  CC      arch/arm/kernel/asm-offsets.s
  GEN     include/generated/asm-offsets.h
  CALL    scripts/checksyscalls.sh
  CC      scripts/mod/empty.o
  HOSTCC  scripts/mod/mk_elfconfig
scripts/mod/mk_elfconfig.c:4:10: fatal error: 'elf.h' file not found
#include <elf.h>
         ^
1 error generated.
make[2]: *** [scripts/mod/mk_elfconfig] Error 1
make[1]: *** [scripts/mod] Error 2
make: *** [scripts] Error 2

Does anyone know how to fix this so that the kernel compilation can continue?

Answer

Derek Gogol picture Derek Gogol · Oct 18, 2013

I'm answering my own question because I found workaround for the missing elf.h file:

cd /Volumes/Android/WORKING_DIRECTORY/external/elfutils/libelf/
$ sudo cp -a elf.h /usr/include

With a copy of 'elf.h' file now in /usr/include the compilation goes on for a while, but then stops again with a different error:

arch/arm/mach-tegra/sleep.S: Assembler messages:
arch/arm/mach-tegra/sleep.S:240: Error: selected processor does not support ARM mode `smc #0'
make[1]: *** [arch/arm/mach-tegra/sleep.o] Error 1
make: *** [arch/arm/mach-tegra] Error 2

Not sure what to do about this last error though.

UPDATE: I gave up on trying to compile Android kernel directly under OS X. Instead, I installed 64-bit Ubuntu on VirtualBox and followed instructions found on this page:

http://forum.xda-developers.com/showthread.php?t=1774035

Except that as I said, I used VirtualBox and not VMWare Player as the above page suggested. It worked great and I didn't have any problems with networking and was able to ssh into Ubuntu to easily move compiled kernel back to OS X.

I also referred to this page to get the right kernel source for my device (grouper), prebuilt gcc and syntax for the make command (make tegra3_android_defconfig):

http://source.android.com/source/building-kernels.html

I hope this answer will save someone some time.