Skip to content

avr linking with precompiled library #7005

Open
@Corjan85

Description

@Corjan85

Hi,
I just tried the upcoming precompiled library feature. I love it, but I noticed a possible bug.

I created a sketch with my own 3 libraries included (HWLib HWLibDriver SiBase), but I kept getting undefined reference errors while linking.

While diving into the problem I noticed the reason:

Link command:

"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-gcc" -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections,--relax -mmcu=atmega2560 "-LC:\Program Files (x86)\Arduino\libraries\HWLib\src\atmega2560" **-lHWLib -lHWLibDriver -lSiBase**  -o "C:\Users\corja\AppData\Local\Temp\arduino_build_576204/sketch_dec10a.ino.elf" "C:\Users\corja\AppData\Local\Temp\arduino_build_576204\sketch\sketch_dec10a.ino.cpp.o" "C:\Users\corja\AppData\Local\Temp\arduino_build_576204/..\arduino_cache_568285\core\core_arduino_avr_mega_cpu_atmega2560_0c812875ac70eb4a9b385d8fb077f54c.a" "-LC:\Users\corja\AppData\Local\Temp\arduino_build_576204" -lm

Error:

C:\Users\corja\AppData\Local\Temp\ccHHlJFj.ltrans0.ltrans.o: In function `setup':
C:\Users\corja\Desktop\sketch\sketch_dec10a/sketch_dec10a.ino:12: undefined reference to `si_hw_lib_tick'
collect2.exe: error: ld returned 1 exit status

Notice that my libraries are included before the object files of the sketch itself.
Since ordering is very important during linking, this is causing the problem

Changing it to this fixes it:

"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-gcc" -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections,--relax -mmcu=atmega2560 "-LC:\Program Files (x86)\Arduino\libraries\HWLib\src\atmega2560" -o "C:\Users\corja\AppData\Local\Temp\arduino_build_576204/sketch_dec10a.ino.elf" "C:\Users\corja\AppData\Local\Temp\arduino_build_576204\sketch\sketch_dec10a.ino.cpp.o" "C:\Users\corja\AppData\Local\Temp\arduino_build_576204/..\arduino_cache_568285\core\core_arduino_avr_mega_cpu_atmega2560_0c812875ac70eb4a9b385d8fb077f54c.a" "-LC:\Users\corja\AppData\Local\Temp\arduino_build_576204" **-lHWLib -lHWLibDriver -lSiBase** -lm

I'm sorry if I am repeating a known bug.

Corjan

Metadata

Metadata

Assignees

Labels

Architecture: AVRApplies only to the AVR microcontrollers (Uno, etc.)Component: CompilationRelated to compilation of Arduino sketchesComponent: CoreRelated to the code for the standard Arduino APIType: Bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions