How to build aarch64 clangd on x86_64 host machine?

With questions like this, one can never confirm too many times. Thank you for being so clear :slight_smile:

Correct, ld-linux-aarch64.so.1 would be the dynamic linker if you were on ARM64.

Here is a command I use for cross compiling lldb in the same way:

LLVM_HOST_BUILD_DIR=/work/open_source/lldb-cross-compile/build-host/

cmake -G Ninja \
  -DCMAKE_SYSTEM_NAME=Linux \
  -DCMAKE_SYSTEM_PROCESSOR=AArch64 \
  -DCMAKE_C_COMPILER=aarch64-unknown-linux-gnu-gcc \
  -DCMAKE_CXX_COMPILER=aarch64-unknown-linux-gnu-g++ \
  -DLLVM_NATIVE_TOOL_DIR=$LLVM_HOST_BUILD_DIR/bin \
  -DLLVM_HOST_TRIPLE=aarch64-unknown-linux-gnu \
  -DLLVM_ENABLE_PROJECTS="clang;lldb" \
  -DCMAKE_LIBRARY_ARCHITECTURE=aarch64-unknown-linux-gnu \
  -DCMAKE_BUILD_TYPE=Release \
  ../llvm-project/llvm

The key settings are:

  • CMAKE_SYSTEM_NAME / CMAKE_SYSTEM_PROCESSOR - when you set these you’re telling CMake that you’re cross compiling. Might not be required but it’ll avoid potential confusion.
  • LLVM_NATIVE_TOOL_DIR - This points to an existing x86 build where you already have tools such as the one your build was trying to run. llvm-tblgen is another common example here.

The others may not be needed, it has been a while since I put that command together.

Once you’ve told CMake you’re cross compiling, and where the native tools are, llvm will decide as appropriate whether to use the native tool instead or just skip it entirely.

If you still have the same error, it would be worth looking at the CMake files that choose to invoke that program and seeing if they check for either of those variables.

1 Like