bug: cross-compile Clang/LLVM for ARM using Clang/LLVM

Hi renato,

  1. The command above is followed by the guide[ HowToCrossCompileLLVM.rst ] and I specify some path(ex. ).

  2. The including x86_64 libraries is added because of some missing libraries(ex. “error: Host compiler appears to require libatomic, but cannot find it”). As I have found that the bugs needed to dealt with is some ARM-dependent libraries, I cannot download them on Ubuntu14, could you share them or some available links?

Thanks very much!

Best,
Liyang

Hi Liyang,

The including x86_64 libraries is added because of some missing libraries

This will never work. The reason the libatomic check is failing is almost certainly because a path to the C++ headers/libraries is missing. You’ve manually added them all:

-I/usr/arm-linux-gnueabihf/include/c++/4.7.3/arm-linux-gnueabihf/ -I/usr/arm-linux-gnueabihf/include/ -I/home/lab/workspace/llvm/llvm-source-code/lib4arm/ -I/home/lab/workspace/llvm/llvm-source-code/lib2ubuntu/ -I/usr/lib/gcc/x86_64-linux-gnu/4.8/libatomic.so -I/usr/lib/gcc/x86_64-linux-gnu/4.8/libatomic.so -L/usr/lib/gcc/x86_64-linux-gnu/4.8/libatomic.so -L/usr/lib/gcc/x86_64-linux-gnu/4.8/libatomic.a

But a much more robust way to do this is just to use a sysroot:

-DCMAKE_CXX_FLAGS=‘-target armv7a-linux-gnueabihf -mcpu=cortex-a9 --sysroot=/usr/arm-linux-gnueabihf/’

Cheers,

James

Hi James, renato,

So how do I download the missing ARM libraries on Ubuntu14.04? I cannot find any available libraries.

Best,
Liyang

You shouldn’t need any. Did you attempt my suggestion ?

Hi James,

  1. I have tried with your suggestion, the command is as follows:

CC=‘clang’ CXX=‘clang++’ cmake -G Ninja …/llvm-source-code
-DCMAKE_CROSSCOMPILING=True
-DCMAKE_INSTALL_PREFIX=./llvm
-DLLVM_TABLEGEN=/home/lab/workspace/llvm/build4x86/bin/llvm-tblgen
-DCLANG_TABLEGEN=/home/lab/workspace/llvm/build4x86/bin/clang-tblgen
-DLLVM_DEFAULT_TARGET_TRIPLE=arm-linux-gnueabihf
-DLLVM_TARGET_ARCH=ARM -DLLVM_TARGETS_TO_BUILD=ARM
-DCMAKE_CXX_FLAGS=‘-target armv7a-linux-gnueabihf -mcpu=cortex-a9 --sysroot=/usr/arm-linux-gnueabihf/ -mfloat-abi=hard -ccc-gcc-name arm-linux-gnueabihf-gcc’
-DLLVM_ENABLE_LIBCXX=ON -DLLVM_ENABLE_PIC=False

But it still produce error, like this:

CMake Error at /home/lab/workspace/cmake-3.2.0-Linux-x86_64/share/cmake-3.2/Modules/CMakeTestCXXCompiler.cmake:54 (message):
The C++ compiler “/home/lab/workspace/llvm/build4x86/bin/clang++” is not
able to compile a simple test program.

/usr/bin/ld: unrecognised emulation mode: armelf_linux_eabi

Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 i386linux elf_l1om
elf_k1om i386pep i386pe

clang-3.9: error: linker command failed with exit code 1 (use -v to see
invocation)

ninja: build stopped: subcommand failed.

  1. If I maually add all the libraries/headers, it don’t produce the errors above.

So I think I still need to download some necessary libraries.

Thanks for your reply!

Best,
Liyang

-DCMAKE_CXX_FLAGS='-target armv7a-linux-gnueabihf -mcpu=cortex-a9
--sysroot=/usr/arm-linux-gnueabihf/ -mfloat-abi=hard -ccc-gcc-name
arm-linux-gnueabihf-gcc'

Try to change the triple to "arm-linux-gnueabihf" as I mentioned
earlier. Clang is getting confused.

/usr/bin/ld: unrecognised emulation mode: armelf_linux_eabi

This is certainly not the ARM linker. :slight_smile:

2. If I maually add all the libraries/headers, it don't produce the errors
above.

If you're using --sysroot, the only library path you may have to use
is /usr/lib/gcc/arm-linux-gnueabihf/VERSION/ due to GCC run-time
libraries.

cheers,
--renato