0
votes

I am trying to cross-compile llvm/clang for Android arm.

I export the CC/CXX variables to the arm-linux-androideabi cross compilers, and then from my build folder I execute:

cmake -G "Unix Makefiles" --target arm-linux-androideabi --sysroot=$NDK/platforms/android-21/arch-arm/ ../llvm 

The build folder is in the same directory with the llvm source code.

I get the error:

rm-linux-androideabi-g++: error: unrecognized command line option '-m32'

I know, it has something to do with g++ multilib for arm-linux but I cannot find it in the NDK.

I have also tried all the steps that are listed here, and the guide found here, with no luck.

Any help would be greatly appreciated. Thanks!

EDIT: NOw I am using the following command:

cmake -G "Unix Makefiles" --prefix=../outarm --target arm-linux-androideabi --sysroot=$NDK/platforms/android-21/arch-arm/ -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PIC=False -DCMAKE_CROSSCOMPILING=True -DLLVM_TABLEGEN=../osxbuild/bin/llvm-tblgen -DCLANG_TABLEGEN=../osxbuild/bin/clang-tblgen -DLLVM_TARGET_ARCH=ARM -DLLVM_TARGETS_TO_BUILD=ARM ../llvm

The compilation now begins, but it stops at 14% with the error:

arm-linux-androideabi-g++: error: unrecognized command line option '-bundle'

EDIT2: I removed all the relative paths to absolute ones. And changed the compiler from gcc to clang. Clang recognises -bundle, but it does not use it. The full command w/ the error now is: Command:

cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=$HOME/Desktop/clang-compilation/outarm -DCMAKE_BUILD_TYPE=Release -DLLVM_DEFAULT_TARGET_TRIPLE=arm-linux-androideabi --sysroot=$NDK/platforms/android-21/arch-arm/ -DLLVM_ENABLE_PIC=False -DLLVM_TARGET_ARCH=ARM -DLLVM_TARGETS_TO_BUILD=ARM -DLLVM_TABLEGEN=$HOME/Desktop/clang-compilation/osxbuild/bin/llvm-tblgen -DCLANG_TABLEGEN=$HOME/Desktop/clang-compilation/osxbuild/bin/clang-tblgen -DCMAKE_CXX_FLAGS='-I$HOME/android/toolchains/gcc/include/c++/4.9/arm-linux-androideabi -I$HOME/android/toolchains/gcc/include/' $HOME/Desktop/clang-compilation/llvm

make -j12

Error message: clang36++: warning: argument unused during compilation: '-bundle' /Users/paschalis/android/toolchains/gcc/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: fatal error: -f/--auxiliary may not be used without -shared

1
After a couple of days fighting w/ cross-compilation flags and dependencies, I managed to get a working compiler. I slightly modified this work, and built clang, gcc, and all of their dependencies! - Paschalis
Can you please point to the script/patches to build clang? - 4ntoine

1 Answers

2
votes

Easiest way to build clang for android is:

  • download AOSP as described here
  • setup build commands from AOSP root (source build/envsetup.sh)
  • cd to platform/external/llvm (see more info here)
  • run mm command to build
  • cd to AOSP root/platform/ndk
  • run build/tools/build-llvm.py (see here)
  • finally package will be in AOSP/out folder