-1

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

Paschalis
  • 11,929
  • 9
  • 52
  • 82
  • After a couple of days fighting w/ cross-compilation flags and dependencies, I managed to get a working compiler. I slightly modified this [work](https://github.com/termux/termux-packages), and built clang, gcc, and all of their dependencies! – Paschalis Jul 31 '15 at 02:41
  • Can you please point to the script/patches to build clang? – 4ntoine Sep 18 '19 at 17:55

1 Answers1

2

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
Laser
  • 6,652
  • 8
  • 54
  • 85
  • Thanks for the suggestion! The problems are mainly caused because some libraries are either missing or stripped down on Android. I `envsetup` and then runned `make clang`. – Paschalis Jul 30 '15 at 19:02
  • @Paschalis do you have any success – Laser Jul 31 '15 at 06:03
  • no. aosp build failed. But thanks anyway! I haven't put much effort though, as I focused on the `termux-packages`. I 've build parts of aosp in the past, just not any external project (successfully) yet! – Paschalis Jul 31 '15 at 13:22
  • 1
    @Paschalis use exactly `mm` command instead of `make` in AOSP – Laser Jul 31 '15 at 13:29
  • Since I 've managed to compile it, I won't try to do it again using the aosp sources. But if you are sure that `mm` works, I 'll take your word and accept this answer! – Paschalis Jul 31 '15 at 13:45