[cfe-dev] Consult how to cross compile clang for arm on x86 linux ubuntu box

David Spickett via cfe-dev cfe-dev at lists.llvm.org
Thu Aug 20 02:38:05 PDT 2020

Hi Andy,

Assuming you are compiling with clang, I think -target and --sysroot
need to be added to CMAKE_CXX_FLAGS instead of being cmake arguments

"However, if you’re using Clang, the driver might not be up-to-date
with your specific Linux distribution, version or GCC layout, so
you’ll need to fudge.

In addition to the ones above, you’ll also need:"

Means you'll need extra CMAKE_CXX_FLAGS. (I also made the same mistake
on first reading) So try:
-DCMAKE_CXX_FLAGS="-target arm-linux-gnueabihf

Also I think (not tried your exact config) you need to tell cmake you
want to use clang by doing:

If you're using GCC, skip the target and sysroot CFLAGS. Also I found
that I had to explicitly give cmake the gcc name (similar to above):
I have a feeling CMake should find this on its own but I don't know
enough to say.

If the default triple is still x86 by that point you can set that
with: -DLLVM_DEFAULT_TARGET_TRIPLE=arm-linux-gnueabihf
(probably won't be an issue)

David Spickett.

On Thu, 20 Aug 2020 at 03:15, Dongdong Yang via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
> I can get llvm source code and the information “cross-compiling from x86_64 to ARM” from https://llvm.org/docs/HowToCrossCompileLLVM.html. However, I still fail to build clang for ARM. It is strange, I have already set a target with "   -target arm-linux-gnueabihf  "  .  I am describing the failure progress as below. Expecting any idea.
> The build steps:
> cd llvm-project
> mkdir build
> cd build
> cmake -DLLVM_ENABLE_PROJECTS=clang -G "Unix Makefiles"
> make
> // After I built host llvm-tblgen  and clang-tblgen, I begin to return to build arm target clang as below steps:
> cd ..
> mkdir build_arm_onx86
> cd build_arm_onx86
> mkdir stall_prefix
> cmake -G "Unix Makefiles" -DCMAKE_CROSSCOMPILING=True  -DCMAKE_INSTALL_PREFIX=./stall_prefix  -DLLVM_TABLEGEN=/home_2t/workspace/llvm_clang/llvm-project/build/bin/llvm-tblgen -DCLANG_TABLEGEN=/home_2t/workspace/llvm_clang/llvm-project/build/bin/clang-tblgen -DLLVM_TARGET_ARCH=ARM -DLLVM_TARGETS_TO_BUILD=ARM  -target arm-linux-gnueabihf  -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi"  ../llvm    2>&1 | tee out_cofiguration.txt
> make  2>&1 | tee out_make.txt
> The result:
> build_arm_onx86$ file bin/clang-12
> bin/clang-12: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=3b669c10e300bb5d9bb96cfb77f927ce95728ca6, not stripped
> build_arm_onx86$ bin/clang --version
> clang version 12.0.0 (https://github.com/llvm/llvm-project.git 3948341fa5fab2695b0df95edc248fe959e40664)
> Target: x86_64-unknown-linux-gnu
> Thread model: posix
> InstalledDir: /home_2t/workspace/llvm_clang/llvm-project/build_arm_onx86/bin
> Seems it failed from the configuration as attached cmake output log.
> -- LLVM host triple: x86_64-unknown-linux-gnu
> -- LLVM default target triple: x86_64-unknown-linux-gnu
> Thanks in advance
> Best Regards,
> Andy
> On Thu, Aug 13, 2020 at 7:32 PM Dongdong Yang <contribute.kernel at gmail.com> wrote:
>> May I ask how to build clang for arm on x86 linux ubuntu box? And how to use  sysroot  to cross compile clang  libc++  for arm on x86 linux?   Appreciate any guidance.
>> Thanks,
>> Andy
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

More information about the cfe-dev mailing list