Rust ESP32C3 Build Error: 'Cannot Find Linker Script link.x'

Hi everyone,

I’m working on an ESP32C3 embedded project, and I’m trying to integrate defmt for logging in my application using the reference defmt book, (Setup - defmt book). when I attempt to build the project, I encounter the following error:

error: linking with `rust-lld` failed: exit status: 1
  = note: rust-lld: error: cannot find linker script link.x

What I have tried:

config.toml:

</[target.riscv32imc-unknown-none-elf]
runner = "espflash flash --monitor"


[env]
ESP_LOGLEVEL="INFO"

[build]
rustflags = [

  "-C", "force-frame-pointers",
  "-C", "link-arg=-Tlink.x",
  "-C", "link-arg=--nmagic",
  "-C", "link-arg=-Tdefmt.x",
]

target = "riscv32imc-unknown-none-elf"

[unstable]
build-std = ["alloc", "core"]

I don’t currently have a link.x file in my project, which seems to be causing the issue. I am not entirely sure where to obtain the correct link.x file for the ESP32C3 or if I need to generate one manually. However I tried on adding link.x from (esp32c3-experiments/esp32c3-link.x at master · MabezDev/esp32c3-experiments · GitHub). But linking with rust-lld failed error still exists.

Is there anything else I should include in the .cargo/config.toml file to properly configure the linker for ESP32C3? Could you help me with any source where I can find or generate the correct link.x linker script. Please do help to troubleshoot the linker script issue and ensure the configuration.

Thank You!

the linker script is supposed to be provided by the runtime crate. for ARM cortex-m series microcontrollers, it's the cortex-m-rt crate; for RISC-V, it's the riscv-rt crate.

I have no experience with the esp32 series, but for RISC-V based products, I think it should be enough to include the riscv-rt crate as a dependency, and its build script should put the linker script at the correct location.

Yes, It's working. Thank you for your valid note.