5

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?

Derek Gogol
  • 1,292
  • 16
  • 15
  • 1
    ... install an elf library? – Carl Norum Oct 17 '13 at 18:53
  • should I install MacPorts? I see **elftoolchain** in there. Or could you point me to stand-alone elf library for OS X? – Derek Gogol Oct 17 '13 at 20:27
  • http://www.mr511.de/software/english.html – Carl Norum Oct 17 '13 at 20:33
  • thanks for the link, I downloaded the latest version of Libelf and installed it, but I still can't find **elf.h** file anywhere. Installation created some files and folders in /usr/local/lib and /usr/local/include, but elf.h is not there. So I'm still getting the same error. – Derek Gogol Oct 17 '13 at 21:05

2 Answers2

6

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.

Derek Gogol
  • 1,292
  • 16
  • 15
2

if you are still interested, check this out http://algobardo.github.io/2014/10/Android-Kernel-MacOsX/ and let me know if it is reproducible on your system with your android version.