[llvm-dev] Cross Compilation Problem

Peter Smith via llvm-dev llvm-dev at lists.llvm.org
Mon Jul 2 02:04:16 PDT 2018


Hello Muhui,

>From what I can see from your commands I think:
- You're missing --target=arm-linux-gnueabi , without that clang will
be building an X86 object and will not expect to be cross compiling.
- --rtlib=compiler-rt will probably not work out of the box. The clang
that you download or build on an X86 machine will not have compiler-rt
libraries for Arm. You can cross compile these and install them into
the clang/7.0.0/lib/linux directory and there is a document to help
you build the builtins at
https://llvm.org/docs/HowToCrossCompileBuiltinsOnArm.html. If you want
to get started quickly I recommend taking out that option.
- You shouldn't need to use sudo to use clang
- I don't think that you need to add -L and -l for the llvm library
directories unless you are actually using the libraries from them.
Beware that the libraries in that directory will probably be compiled
for X86 so won't be of much use to you on an Arm system.

Just to make sure you are aware, the arm-linux-gnueabi gcc tooltchain
has soft-floating point libraries. If you want hard floating point
libraries, such as used on the Raspberry Pi, you'll need the
arm-linux-gnueabihf gcc toolchain and to use
--target=arm-linux-gnueabihf.

Depending on how simple your test.c is I suggest:
/home/jmh/Downloads/llvm/build/bin/clang --target=arm-linux-gnueabi
--sysroot=/home/jmh/Downloads/gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabi/arm-linux-gnueabi/libc
--gcc-toolchain=/home/jmh/Downloads/gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabi/lib/gcc/arm-linux-gnueabi/
-target arm-linux-gnueabi -fuse-ld=lld -o test test.c

Hope this gets you a little bit further.

Peter

On 1 July 2018 at 18:19, Muhui Jiang <jiangmuhui at gmail.com> wrote:
> Hi Peter
>
> I guess this is the document written by you
> https://fosdem.org/2018/schedule/event/crosscompile/attachments/slides/2107/export/events/attachments/crosscompile/slides/2107/How_to_cross_compile_with_LLVM_based_tools.pdf
>
> I follow it to try to use the clang to do cross compilation. Actually, my
> target binaries is SPECCPU2006 and autotools based binaries.
>
> However, I failed on the first step. I write a hello world as test.c.  I
> refer to your document and download the newest version of arm toolchain.
>
> I use the following command to try to compile the code to binary.
>
> sudo /home/jmh/Downloads/llvm/build/bin/clang
> --sysroot=/home/jmh/Downloads/gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabi/arm-linux-gnueabi/libc
> --gcc-toolchain=/home/jmh/Downloads/gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabi/lib/gcc/arm-linux-gnueabi/
> -target arm-linux-gnueabi -fuse-ld=lld -L /home/jmh/Downloads/llvm/build/lib
> -I/home/jmh/Downloads/llvm/build/include/ --rtlib=compiler-rt -o test test.c
>
> However, I come across the following exception.
>
> /home/jmh/Downloads/llvm/build/bin/ld.lld: error: cannot open crtbegin.o: No
> such file or directory
> /home/jmh/Downloads/llvm/build/bin/ld.lld: error: cannot open
> /home/jmh/Downloads/llvm/build/lib/clang/7.0.0/lib/linux/libclang_rt.builtins-arm.a:
> No such file or directory
> /home/jmh/Downloads/llvm/build/bin/ld.lld: error: cannot open
> /home/jmh/Downloads/llvm/build/lib/clang/7.0.0/lib/linux/libclang_rt.builtins-arm.a:
> No such file or directory
> /home/jmh/Downloads/llvm/build/bin/ld.lld: error: cannot open crtend.o: No
> such file or directory
> clang-7: error: linker command failed with exit code 1 (use -v to see
> invocation)
>
> Do you have any ideas or suggestions. I also cc the problem to llvm
> community. Anyone who has the same experience. Please help me. Many Thanks
>
> Regards
> Muhui
>
>


More information about the llvm-dev mailing list