clang+cmake not working under windows (ESP32-C3/RISC-V)

MicroController
Posts: 1708
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

clang+cmake not working under windows (ESP32-C3/RISC-V)

Postby MicroController » Sun Apr 09, 2023 12:43 pm

I try and fail to get clang (esp-llvm) to work under windows for the ESP32-C3: cmake fails while (re-)configuring the project, saying clang "is not able to compile a simple test program."

Apparently because it tries to link in runtime libraries which are not there, specifically

Code: Select all

clang_rt.crtbegin-riscv32.o
libclang_rt.builtins-riscv32.a
clang_rt.crtend-riscv32.o
whilch don't exist anywhere on my machine.

ESP-IDF v5.1, Windows,

Code: Select all

* esp-clang: Toolchain for all Espressif chips based on clang (optional)
  - 15.0.0-23786128ae (recommended, installed)

CMakeError.log:

Code: Select all

cmd.exe /C "cd . && D:\Espressif\tools\esp-clang\15.0.0-23786128ae\esp-clang\bin\clang.exe --target=riscv32-esp-elf -march=rv32imc -mabi=ilp32 -v CMakeFiles/cmTC_c8f86.dir/CMakeCCompilerABI.c.obj -o cmTC_c8f86   && cd ."
clang version 15.0.0 (https://github.com/espressif/llvm-project.git 23786128aea96880a5752f6bd1c22aab27622ccf)
Target: riscv32-esp-unknown-elf
Thread model: posix
InstalledDir: D:/Espressif/tools/esp-clang/15.0.0-23786128ae/esp-clang/bin
Found candidate GCC installation: D:/Espressif/tools/esp-clang/15.0.0-23786128ae/esp-clang/bin/../lib/gcc/riscv32-esp-elf/11.2.0
Selected GCC installation: D:/Espressif/tools/esp-clang/15.0.0-23786128ae/esp-clang/bin/../lib/gcc/riscv32-esp-elf/11.2.0
Candidate multilib: .;
Candidate multilib: no-rtti;@fno-rtti
Candidate multilib: rv32i/ilp32;@march=rv32i@mabi=ilp32
Candidate multilib: rv32i/ilp32/no-rtti;@march=rv32i@mabi=ilp32@fno-rtti
Candidate multilib: rv32imc/ilp32;@march=rv32imc@mabi=ilp32
Candidate multilib: rv32imc/ilp32/no-rtti;@march=rv32imc@mabi=ilp32@fno-rtti
Candidate multilib: rv32imafc/ilp32f;@march=rv32imafc@mabi=ilp32f
Candidate multilib: rv32imafc/ilp32f/no-rtti;@march=rv32imafc@mabi=ilp32f@fno-rtti
Selected multilib: rv32imc/ilp32;@march=rv32imc@mabi=ilp32
 "D:/Espressif/tools/esp-clang/15.0.0-23786128ae/esp-clang/bin/ld.lld" -m elf32lriscv -X D:/Espressif/tools/esp-clang/15.0.0-23786128ae/esp-clang/bin/../lib/gcc/riscv32-esp-elf/11.2.0/../../../../riscv32-esp-elf/lib/rv32imc/ilp32/crt0.o D:/Espressif/tools/esp-clang/15.0.0-23786128ae/esp-clang/lib/clang/15.0.0/lib/clang_rt.crtbegin-riscv32.o CMakeFiles/cmTC_c8f86.dir/CMakeCCompilerABI.c.obj -LD:/Espressif/tools/esp-clang/15.0.0-23786128ae/esp-clang/bin/../lib/gcc/riscv32-esp-elf/11.2.0/rv32imc/ilp32 -LD:/Espressif/tools/esp-clang/15.0.0-23786128ae/esp-clang/bin/../lib/gcc/riscv32-esp-elf/11.2.0/../../../../riscv32-esp-elf/lib/rv32imc/ilp32 -LD:/Espressif/tools/esp-clang/15.0.0-23786128ae/esp-clang/bin/../lib/gcc/riscv32-esp-elf/11.2.0 -LD:/Espressif/tools/esp-clang/15.0.0-23786128ae/esp-clang/bin/../lib/gcc/riscv32-esp-elf/11.2.0/../../../../riscv32-esp-elf/lib --start-group -lc -lgloss -lnosys --end-group D:/Espressif/tools/esp-clang/15.0.0-23786128ae/esp-clang/lib/clang/15.0.0/lib/libclang_rt.builtins-riscv32.a D:/Espressif/tools/esp-clang/15.0.0-23786128ae/esp-clang/lib/clang/15.0.0/lib/clang_rt.crtend-riscv32.o -o cmTC_c8f86
ld.lld: error: cannot open D:/Espressif/tools/esp-clang/15.0.0-23786128ae/esp-clang/lib/clang/15.0.0/lib/clang_rt.crtbegin-riscv32.o: No such file or directory
ld.lld: error: cannot open D:/Espressif/tools/esp-clang/15.0.0-23786128ae/esp-clang/lib/clang/15.0.0/lib/libclang_rt.builtins-riscv32.a: No such file or directory
ld.lld: error: cannot open D:/Espressif/tools/esp-clang/15.0.0-23786128ae/esp-clang/lib/clang/15.0.0/lib/clang_rt.crtend-riscv32.o: No such file or directory
clang: error: ld command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
Any pointer as to how to get clang working greatly appreciated :)

MicroController
Posts: 1708
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: clang+cmake not working under windows (ESP32-C3/RISC-V)

Postby MicroController » Thu Apr 13, 2023 12:44 pm

I figure I'd have to convince the toolchain to link in gcc's rt libs instead of the corresponding clang_rt.*.

But I cannot seem to find where the reference to clang_rt is coming from.

sleepasloth
Posts: 1
Joined: Sun Jan 28, 2024 11:40 am

Re: clang+cmake not working under windows (ESP32-C3/RISC-V)

Postby sleepasloth » Sun Jan 28, 2024 11:49 am

I am facing the same issue with an ESP32. Can anyone help building with Clang on Windows?

Code: Select all

C:\dev\espressif\frameworks\esp-idf-v5.1\tools\check_python_dependencies.py:12: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  import pkg_resources
Executing action: all (aliases: build)
Running cmake in directory C:\dev\esp32\test\build
Executing "cmake -G Ninja -DPYTHON_DEPS_CHECKED=1 -DPYTHON=C:\dev\espressif\python_env\idf5.1_py3.11_env\Scripts\python.exe -DESP_PLATFORM=1 -DCCACHE_ENABLE=1 C:\dev\esp32\test"...
-- IDF_TARGET is not set, guessed 'esp32' from sdkconfig 'C:/dev/esp32/test/sdkconfig'
-- Found Git: C:/dev/espressif/tools/idf-git/2.39.2/cmd/git.exe (found version "2.39.2.windows.1")
-- ccache will be used for faster recompilation
-- The C compiler identification is Clang 15.0.0
-- The CXX compiler identification is Clang 15.0.0
-- The ASM compiler identification is Clang with GNU-like command-line
-- Found assembler: C:/dev/espressif/tools/esp-clang/15.0.0-23786128ae/esp-clang/bin/clang.exe
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/dev/espressif/tools/esp-clang/15.0.0-23786128ae/esp-clang/bin/clang.exe
-- Check for working C compiler: C:/dev/espressif/tools/esp-clang/15.0.0-23786128ae/esp-clang/bin/clang.exe - broken
CMake Error at C:/dev/espressif/tools/cmake/3.24.0/share/cmake-3.24/Modules/CMakeTestCCompiler.cmake:69 (message):
  The C compiler

    "C:/dev/espressif/tools/esp-clang/15.0.0-23786128ae/esp-clang/bin/clang.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: C:/dev/esp32/test/build/CMakeFiles/CMakeTmp

    Run Build Command(s):C:/dev/espressif/tools/ninja/1.10.2/ninja.exe cmTC_d3ea1 && [1/2] Building C object CMakeFiles/cmTC_d3ea1.dir/testCCompiler.c.obj
    [2/2] Linking C executable cmTC_d3ea1
    FAILED: cmTC_d3ea1
    cmd.exe /C "cd . && C:\dev\espressif\tools\esp-clang\15.0.0-23786128ae\esp-clang\bin\clang.exe --target=xtensa-esp-elf -mcpu=esp32  CMakeFiles/cmTC_d3ea1.dir/testCCompiler.c.obj -o cmTC_d3ea1   && cd ."
    ld.lld: error: cannot open C:/dev/espressif/tools/esp-clang/15.0.0-23786128ae/esp-clang/lib/clang/15.0.0/lib/clang_rt.crtbegin-xtensa.o: No such file or directory
    ld.lld: error: cannot open C:/dev/espressif/tools/esp-clang/15.0.0-23786128ae/esp-clang/lib/clang/15.0.0/lib/libclang_rt.builtins-xtensa.a: No such file or directory
    ld.lld: error: cannot open C:/dev/espressif/tools/esp-clang/15.0.0-23786128ae/esp-clang/lib/clang/15.0.0/lib/clang_rt.crtend-xtensa.o: No such file or directory
    clang: error: ld command failed with exit code 1 (use -v to see invocation)
    ninja: build stopped: subcommand failed.

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  C:/dev/espressif/frameworks/esp-idf-v5.1/tools/cmake/project.cmake:365 (__project)
  CMakeLists.txt:8 (project)

-- Configuring incomplete, errors occurred!
See also "C:/dev/esp32/test/build/CMakeFiles/CMakeOutput.log".
See also "C:/dev/esp32/test/build/CMakeFiles/CMakeError.log".
cmake failed with exit code 1, output of the command is in the C:\dev\esp32\test\build\log\idf_py_stderr_output_21228 and C:\dev\esp32\test\build\log\idf_py_stdout_output_21228

Who is online

Users browsing this forum: No registered users and 76 guests