After installing the arm-linux-gnueabihf toolchain of gcc and g++, I tried cross-compiling with clang.
clang-10,
clang++ --target=arm-linux-gnueabihf h.cpp -o r
Works just as expected, but
clang-14.0.6,
/home/path/to/llvm-project/bin/clang --target=arm-linux-gnueabihf hello.cpp -o r
is not,
error: unable to create target: 'No available targets are compatible with triple "armv6kz-unknown-linux-gnueabihf"'
What I tried,
clang++ --target=arm-linux-gnueabihf -stdlib=libstdc++ hello.cpp -o r
error: unable to create target: 'No available targets are compatible with triple "armv6kz-unknown-linux-gnueabihf"'
1 error generated.
Forced clang to use latest toolchain downloaded from official website: arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf.tar.xz.
clang++ --sysroot=/home/path/to/toolchain/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/bin -stdlib=libstdc++ h.cpp -o r
fatal error: 'iostream' file not found
#include<iostream>
^~~~~~~~~~
1 error generated.
Also tried using the linaro gcc toolchain, specifically this one - gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf.tar.xz
Here is the verbose output,
clang++ --target=arm-linux-gnueabihf -stdlib=libstdc++ hello.cpp -o hello --verbose
clang version 15.0.0 (https://github.com/llvm/llvm-project.git df6afee9859f982fa927dc90398e82d689f19db6)
Target: arm-unknown-linux-gnueabihf
Thread model: posix
InstalledDir: /usr/local/bin
Found candidate GCC installation: /usr/lib/gcc-cross/arm-linux-gnueabihf/10
Selected GCC installation: /usr/lib/gcc-cross/arm-linux-gnueabihf/10
Candidate multilib: .;@m32
Selected multilib: .;@m32
"/usr/local/bin/clang-15" -cc1 -triple armv6kz-unknown-linux-gnueabihf -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -main-file-name ex.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-cpu arm1176jzf-s -target-feature +vfp2 -target-feature +vfp2sp -target-feature -vfp3 -target-feature -vfp3d16 -target-feature -vfp3d16sp -target-feature -vfp3sp -target-feature -fp16 -target-feature -vfp4 -target-feature -vfp4d16 -target-feature -vfp4d16sp -target-feature -vfp4sp -target-feature -fp-armv8 -target-feature -fp-armv8d16 -target-feature -fp-armv8d16sp -target-feature -fp-armv8sp -target-feature -fullfp16 -target-feature +fp64 -target-feature -d32 -target-feature -neon -target-feature -sha2 -target-feature -aes -target-feature -fp16fml -target-feature +strict-align -target-abi aapcs-linux -mfloat-abi hard -Wunaligned-access -fallow-half-arguments-and-returns -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -v -fcoverage-compilation-dir=/home/usr/test -resource-dir /usr/local/lib/clang/15.0.0 -internal-isystem /usr/lib/gcc-cross/arm-linux-gnueabihf/10/../../../../arm-linux-gnueabihf/include/c++/10 -internal-isystem /usr/lib/gcc-cross/arm-linux-gnueabihf/10/../../../../arm-linux-gnueabihf/include/c++/10/arm-linux-gnueabihf -internal-isystem /usr/lib/gcc-cross/arm-linux-gnueabihf/10/../../../../arm-linux-gnueabihf/include/c++/10/backward -internal-isystem /usr/local/lib/clang/15.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc-cross/arm-linux-gnueabihf/10/../../../../arm-linux-gnueabihf/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir=/home/usr/test -ferror-limit 19 -fno-signed-char -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/ex-bae03b.o -x c++ ex.cpp
clang -cc1 version 15.0.0 based upon LLVM 15.0.0git default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc-cross/arm-linux-gnueabihf/10/../../../../arm-linux-gnueabihf/include/c++/10
/usr/lib/gcc-cross/arm-linux-gnueabihf/10/../../../../arm-linux-gnueabihf/include/c++/10/arm-linux-gnueabihf
/usr/lib/gcc-cross/arm-linux-gnueabihf/10/../../../../arm-linux-gnueabihf/include/c++/10/backward
/usr/local/lib/clang/15.0.0/include
/usr/local/include
/usr/lib/gcc-cross/arm-linux-gnueabihf/10/../../../../arm-linux-gnueabihf/include
/usr/include
End of search list.
error: unable to create target: 'No available targets are compatible with triple "armv6kz-unknown-linux-gnueabihf"'
1 error generated.
Just some simple instructions that can be important
I built llvm from source using this,
cmake -G Ninja -DLLVM_ENABLE_RTTI=ON -DLLVM_ENABLE_EH=ON -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PROJECTS="llvm;clang" ../llvm