Solution for adding support for pre-compiled Libraries

Status
Not open for further replies.

Blackaddr

Well-known member
Anyone know which of Paul's repos on Github is for the Teensyduino files with regards to the following file. I can't seem to find which one it is and I'd like to make a pull request to get support for precompiled libraries working.

hardware/teensy/avr/platform.txt

Arduino IDE added support for precompiled libraries, it was discussed here previously, but there is an easier solution (see below):
https://forum.pjrc.com/threads/50172-How-to-add-a-pre-compiled-library

I really need to use precompiled libraries for a project so I looked into this, it's actually pretty easy to solve now. I used this very helpful link as a reference:
https://forum.arduino.cc/index.php?topic=653746.0

TL;DR

The following changes must be made to the platform.txt file:

1) Insert {compiler.libraries.ldflags} in the correct loocation to the recipe.c.combine.pattern, after the {object_files}
Code:
## Link
recipe.c.combine.pattern="{compiler.path}{build.toolchain}{build.command.linker}" {build.flags.optimize} {build.flags.ld} {build.flags.ldspecs} {build.flags.cpu} -o "{build.path}/{build.project_name}.elf" {object_files} {compiler.libraries.ldflags} "{build.path}/{archive_file}" "-L{build.path}" {build.flags.libs}

2) Add 'compiler.libraries.ldflags=' to the platform.txt file, I threw it at the end
Code:
compiler.libraries.ldflags=

That's it for changes to Teensyduino.

3) To build your library, you must add the following option to your library.properties file in order to have the compiler output the static library .a file.
Code:
dot_a_linkage=true

4) Compile the library and go grab the YourLibrary.a file from /tmp/<build otuput>

5) Package up (zip) your library as follows:
MyLibrary/library.properties
MyLibrary/src/<arch>/libYourLibrary.a
MyLibrary/src/<public header files only>

5a) remove the dot_a_linkage in your packaged version and replace with the following two lines:
Code:
precompiled=true
ldflags=-lMyLibrary
5b) figure our the arch you targeting. For example for Teensy 4.X, its 'imxrt1062'. You need to separately compile and package for each architecture you are targeting.
5c) notice we have to rename YourLibrary.a to libYourLibrary.a in the package.

You can do these steps yourself in the meantime. If I can get a pull request to update the platform.txt file in Teensyduino, Steps 1 & 2 would already be done.
 
Bumping this again. @Paul

Any chance of getting his update permanently added to the Teensy's platform.txt? It's seems it should be low risk, shouldn't break anything and bring it up to date with the the platform.txt of other Arduino platforms.

This change is also necessary to support the 'precompiled' and 'ldflags' keywords in the library.properties file as part of the latest Arduino Library Specification (rev 2.2)
https://arduino.github.io/arduino-cli/library-specification/

This change gathers the 'ldflags=' list from the library.properties and add it to the linker list of libraries.

The project I'm working on requires libraries that use these properties and my collaborators and I have to manually edit our platform.txt with every new Teensyduino release.
 
Status
Not open for further replies.
Back
Top