Cross compile x64 to AArch64 issues

Hi,

I am trying to cross compile release-10.x to AArch64
(target=aarch64-linux-gnu), and the directions listed at [1] are not
completing the initial cmake step. I'm currently running Manjaro,
with the aarch64-linux-gnu package (and associated binutils, headers,
and glibc packages). My cmake command is

cmake -DCMAKE_CROSSCOMPILING=True -DCMAKE_INSTALL_PREFIX=`realpath
install` -DLLVM_TABLEGEN=`realpath
../build-10.x/install/bin/llvm-tblgen`
-DLLVM_DEFAULT_TARGET_TRIPLE=aarch64-linux-gnu
-DLLVM_TARGET_ARCH=AArch64 -DLLVM_TARGETS_TO_BUILD=AArch64
-DCMAKE_CXX_FLAGS="-target aarch64-linux-gnu
--sysroot=/usr/aarch64-linux-gnu
-L/usr/lib/gcc/aarch64-linux-gnu/10.1.0" -DCMAKE_C_COMPILER=`realpath
../build-10.x/install/bin/clang` -DCMAKE_CXX_COMPILER=`realpath
../build-10.x/install/bin/clang++`
-DLLVM_ENABLE_PROJECTS="compiler-rt" -DLLVM_ENABLE_ZLIB=False
-DLLVM_INCLUDE_TESTS=False -G Ninja ../llvm

Does anyone see any obvious misconfiguration? Cmake fails at the
early test for a working CXX compiler:

/usr/bin/aarch64-linux-gnu-ld: cannot find crtbegin.o: No such file or directory

I have confirmed that crtbegin.o exists in /usr/lib/gcc/aarch64-linux-gnu/10.1.0

If I copy /usr/lib/gcc/aarch64-linux-gnu/10.1.0/{crtbegin,crtend}.o to
/usr/aarch64-linux-gnu/lib the check passed, but then the
LLVM_LIBSTDCXX_MIN check fails. However, checking CMakeErrors.log,
the failing program can be compiled with my system
aarch64-linux-gnu-g++. Barring any misconfiguration, I think that the
build system is not correctly using the sysroot and gcc-toolchain
paths correctly.

[1]: https://llvm.org/docs/HowToCrossCompileLLVM.html

Hello,

I would recommend checking the CMake documentation about cross compiling and creating a CMake toolchain file.

The current flags you pass are not instructing CMake about the config checks.

https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html

Hope this helps!

Hi,

I often cross compile and there’s also some issue! Have you tried passing your library path to -DCMAKE_EXE_LINKER_FLAGS? I’ve sometimes also used the -B option to override the default paths.

Regards,
sam