Linking with `avr-gcc` failed: exit code: 1

background:

in avr-hal template app, use cc-rs compile arduino api to static archive, use bindgen export those apis, then I can use those apis in rust project.

problem:

error: linking with avr-gcc failed: exit code: 1
|
= note: "avr-gcc" "-mmcu=atmega328p" "C:\Users\atmel\AppData\Local\Temp\rustc1tjpKG\symbols.o" "D:\home\atmel\temp\arduino-cross\abc\target\avr-atmega328p\debug\deps\abc-107fcf5e3cc83643.arduino_hal-4188a2b374ff51cb.arduino_hal.925376be7d49da03-cgu.0.rcgu.o.rcgu.o" "-Wl,--as-needed" "-L" "D:\home\atmel\temp\arduino-cross\abc\target\avr-atmega328p\debug\deps" "-L" "D:\home\atmel\temp\arduino-cross\abc\target\debug\deps" "-L" "D:\home\atmel\temp\arduino-cross\abc\arduino-lib\packages\arduino\hardware\avr\1.8.6\cores\arduino\uno" "-L" "C:\Users\atmel\.rustup\toolchains\nightly-2023-12-28-x86_64-pc-windows-msvc\lib\rustlib\avr-atmega328p\lib" "-Wl,-Bstatic" "-lcore_s" "-lcore_c" "-lcore_cpp" "-lexternal_cpp" "-Wl,-Bdynamic" "-lgcc" "-Wl,-z,noexecstack" "-L" "C:\Users\atmel\.rustup\toolchains\nightly-2023-12-28-x86_64-pc-windows-msvc\lib\rustlib\avr-atmega328p\lib" "-o" "D:\home\atmel\temp\arduino-cross\abc\target\avr-atmega328p\debug\deps\abc-107fcf5e3cc83643.elf" "-Wl,--gc-sections" "-no-pie"
= note: c:/users/atmel/appdata/local/arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld.exe: 2c37ec98d4728a37-wiring_digital.o: plugin needed to handle lto object
c:/users/atmel/appdata/local/arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld.exe: 2c37ec98d4728a37-WMath.o: plugin
needed to handle lto object
C:\Users\atmel\AppData\Local\Temp\ccwIJprK.ltrans0.ltrans.o: In function __vector_11': <artificial>:(.text+0x100): undefined reference to digitalWrite'
:(.text+0x172): undefined reference to `digitalWrite'
collect2.exe: error: ld returned 1 exit status

= note: some extern functions couldn't be found; some native libraries may need to be installed or have their path specified
= note: use the -l flag to specify native libraries to link
= note: use the cargo:rustc-link-lib directive to specify the native libraries to link with Cargo (see Build Scripts - The Cargo Book)

more info

the report tell me that can not find digitalWrite. but I have found it in the outputed archive:

atmel@atmel-PC MINGW64 /d/home/atmel/temp/arduino-cross/abc/arduino-lib/packages/arduino/hardware/avr/1.8.6/cores/arduino/uno (main)
$ llvm-objdump -t libcore_c.a | grep -i digitalwrite
00000000 l    d  .gnu.lto_digitalWrite.49ad5d90 00000000 .gnu.lto_digitalWrite.49ad5d90

pls help me solve it.

I have solved it. the cause of the problem is:

  1. Compile object and final app using the "-lto"
  2. each module is packaged into an independent archive

so I need to archive all modules object into one archive, then link the archive to the fianll app.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.