Skip to content

avr linking with precompiled library #7005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Corjan85 opened this issue Dec 10, 2017 · 3 comments
Open

avr linking with precompiled library #7005

Corjan85 opened this issue Dec 10, 2017 · 3 comments
Assignees
Labels
Architecture: AVR Applies only to the AVR microcontrollers (Uno, etc.) Component: Compilation Related to compilation of Arduino sketches Component: Core Related to the code for the standard Arduino API Type: Bug

Comments

@Corjan85
Copy link

Corjan85 commented Dec 10, 2017

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

@Corjan85
Copy link
Author

Corjan85 commented Dec 10, 2017

My library.properties:

name=SI Custom Device
version=1.0.0
author=Sim Innovations
maintainer=Sim Innovations <[email protected]>
sentence=Allows to couple custom Arduino projects to Air Manager or Air Player
paragraph=TODO
category=Device Control
url=https://www.siminnovations.com
architectures=*
precompiled=true
ldflags=-lHWLib -lHWLibDriver -lSiBase

@per1234
Copy link
Collaborator

per1234 commented Dec 10, 2017

I believe this has been reported to the SAM and SAMD cores but not yet regarding the AVR core:
arduino/ArduinoCore-sam#46
arduino/ArduinoCore-samd#278

@per1234 per1234 added the Component: Compilation Related to compilation of Arduino sketches label Dec 10, 2017
@Corjan85
Copy link
Author

Corjan85 commented Dec 11, 2017

Hi,
Thanks for your quick response, and sorry about the other threads. I should have searched better.

Just checked the platform.txt in the ArduinoCore-avr github, but that platform.txt does not seem to be correct (just yet).

I believe line 68 should be replaced by this line:

recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mmcu={build.mcu} -o "{build.path}/{build.project_name}.elf" {object_files} {compiler.c.elf.extra_flags} "{build.path}/{archive_file}" "-L{build.path}" -lm

The link order would be:

  • sketch objects
  • precompiled library objects
  • Arduino core objects

That way a precompiled library can also use features from the ArduinoCore library.

Corjan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Architecture: AVR Applies only to the AVR microcontrollers (Uno, etc.) Component: Compilation Related to compilation of Arduino sketches Component: Core Related to the code for the standard Arduino API Type: Bug
Projects
None yet
Development

No branches or pull requests

3 participants