Skip to content

[clang][docs] Specify minimum CMake version for cross compiling #165253

@blabdouze

Description

@blabdouze

The instructions found here https://llvm.org/docs/HowToCrossCompileLLVM.html tell us to set the CMake variable CMAKE_LINKER_TYPE which is only supported since CMake 3.29.

On Ubuntu 22.04 provided CMake is version 3.22 making the cross compilation fail when configurating the project :

cmake -G Ninja \
  -DCMAKE_BUILD_TYPE=Release \
  -DLLVM_ENABLE_PROJECTS="lld;clang;clang-tools-extra" \
  -DCMAKE_TOOLCHAIN_FILE=$TARGET-clang.cmake \
  -DLLVM_HOST_TRIPLE=$TARGET \
  -DCMAKE_INSTALL_PREFIX=$HOME/clang-$TARGET \
  -S llvm \
  -B build/$TARGET
-- The C compiler identification is Clang 21.1.5
-- The CXX compiler identification is Clang 21.1.5
-- The ASM compiler identification is Clang with GNU-like command-line
-- Found assembler: /usr/bin/clang-21
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /usr/bin/clang-21
-- Check for working C compiler: /usr/bin/clang-21 - broken
CMake Error at /usr/share/cmake-3.22/Modules/CMakeTestCCompiler.cmake:69 (message):
  The C compiler

    "/usr/bin/clang-21"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/dev/llvm-project/build/arm-linux-gnueabihf/CMakeFiles/CMakeTmp

    Run Build Command(s):/usr/bin/ninja cmTC_683fc && [1/2] Building C object CMakeFiles/cmTC_683fc.dir/testCCompiler.c.o
    [2/2] Linking C executable cmTC_683fc
    FAILED: cmTC_683fc
    : && /usr/bin/clang-21 --target=arm-linux-gnueabihf --sysroot=/home/dev/sysroot-deb-armhf-stable   CMakeFiles/cmTC_683fc.dir/testCCompiler.c.o -o cmTC_683fc   && :
    /usr/bin/ld: unrecognised emulation mode: armelf_linux_eabi
    Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 elf_iamcu elf_l1om elf_k1om i386pep i386pe
    clang-21: error: linker command failed with exit code 1 (use -v to see invocation)
    ninja: build stopped: subcommand failed.

With CMake 4.1 it works as expected :

 /home/dev/llvm-project/cmake-4.1.2-linux-x86_64/bin/cmake -G Ninja \
  -DCMAKE_BUILD_TYPE=Release \
  -DLLVM_ENABLE_PROJECTS="lld;clang;clang-tools-extra" \
  -DCMAKE_TOOLCHAIN_FILE=$PWD/$TARGET-clang.cmake \
  -DLLVM_HOST_TRIPLE=$TARGET \
  -DCMAKE_INSTALL_PREFIX=$HOME/clang-$TARGET \
  -S llvm \
  -B build/$TARGET
-- The C compiler identification is Clang 21.1.5
-- The CXX compiler identification is Clang 21.1.5
-- The ASM compiler identification is Clang with GNU-like command-line
-- Found assembler: /usr/bin/clang-21
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/clang-21 - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/clang++-21 - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- bolt project is disabled
-- clang project is enabled
-- clang-tools-extra project is enabled
-- compiler-rt project is disabled
-- cross-project-tests project is disabled
-- libclc project is disabled
-- lld project is enabled
-- lldb project is disabled
-- mlir project is disabled
-- openmp project is disabled
-- polly project is disabled
-- flang project is disabled
-- libc project is disabled
-- Found Python3: /usr/bin/python3.10 (found suitable version "3.10.12", minimum required is "3.8") found components: Interpreter
...

A line should specify the minimum version of CMake that can be used to cross compile (as done in : https://llvm.org/docs/CMake.html#quick-start)

Metadata

Metadata

Assignees

No one assigned

    Labels

    clangClang issues not falling into any other categorydocumentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions