Using precompiled library

I would like to take advantage of this feature to reduce compile times with Arduino IDE 2.2.1.

I've read the Arduino CLI Library Specification, searched the forum and Google for "precompiled library", "The platform does not support 'compiler.libraries.ldflags'", found numerous posts about fixing it, but nothing I've tried has worked.

The target board is a Sparkfun Redboard Artemis ATP (aka apollo3).

I have a simple test.ino program that includes one library to test with:

//test.ino
#include <Utils.h>

void setup() {
}

void loop() {
}

The compiler finds my library no problem. This is a snipet of what I get in the output window:
[...]
Compiling libraries...
Compiling library "Utils Library"
Library Utils Library has been declared precompiled:
Using precompiled library in d:\Projects\Arduino\libraries\Utils\src
The platform does not support 'compiler.libraries.ldflags' for precompiled libraries.
[...]

In libraries\Utils I have these files/folders:
src (folder)
library.properties

library.properties contains this:
name=Utils Library
version=0.0.0
author=lahr
maintainer=lahr <lahr@~~~~~~.~>
sentence=Utils Library
paragraph=Provides Common GP Utilities
category=Other
url=
architectures=*
depends=
dot_a_linkage=true
precompiled=full

In the src folder I have these files:
libUtils.a
Utils.cpp
Utils.h

I've searched my C: drive for every instance of platform.txt and copied a platform.local.txt file into those folders that contains this line:
compiler.libraries.ldflags=

When that didn't fix it I also tried editing every platform.txt file to add the above line, and to modify the recipe.c.combine.pattern line:
recipe.c.combine.pattern="{compiler.gcc.cmd}" "-T{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" -o "{build.path}/{build.project_name}.axf" {object_files} {libs.all} {compiler.ld.flags} {compiler.libraries.ldflags} {defines.ld}

I have spent about 4 hours chasing this problem, and no change. Is it possible to do this with IDE v2.2.1?

Thanks!
Larry

I think you’re trying to solve a problem that you don’t have. Once the source code for a library has been compiled once, it shouldn’t be compiled again unless that source code is changed. The makefile maintained by the IDE should take care of that.

The use case for a pre-compiled library is when it’s distributed as only relocatable object code and a header file (no source code). This could be the case for proprietary software which is not the norm in Arduino Land.

1 Like

However true that might be, your answer doesn't solve the problem, but I thank you for taking the time to post your response.

My observations and the compile log tend to indicate that the IDE does in fact recompile everything, including the Arduino libraries such as Wire and SPI, each and every time.

I do like the speed at which VS Code compiles, but I hate all things Microsoft and would rather endure the long compile times of the Arduino IDE rather than use it.

Ultimately, I would like to develop a pre-compiled library, for my use, and potentially for licensed distribution to our customers. I have been programming machines for over 30 years, and I would like to build libraries of functions and methods I use routinely. I don't want my customers poking around in the source code because they tend to cause problems that I then have to solve to prove I wasn't at fault.

Sorry for the long response.
Larry

"No matter how bad Windows gets, I still prefer Linux."

Be careful about incorporating Open Source-licensed code from Arduino (pretty much the entire Arduino core) and other places into your proprietary library and then not releasing the source code. There have been many discussions about that in this forum and I don't pretend to understand it even superficially. But it sounds like a sticky wicket.

You are absolutely right. For that reason, I create my own libraries to avoid potential copyright infringement. I'm not talking rewriting something like Wire, I'm talking about code to run a custom built machine for a specific purpose, like a water treatment system, or a product packaging machine, or an ID card printer. Off the shelf control systems for applications like this cost $10,000 plus. I can duplicate these systems using Arduino components for 1/10th the cost. That's the appeal for me.

It's been a few decades since I touched C code, so I'm very rusty but really enjoying it.

Thanks again for the response!
Larry

It may be an issue with the toolchain used by Artemis. I would try asking on the Sparkfun forum.

ETA: I just tried a similar example to yours with Uno and IDE 2.2.1, and it worked as expected, except I had to put the Utils.a in src/atmeag328p. Then the library was detected and apparently used. I don't know if architecture sub-folder is required for your toolchain.

Also, although the IDE does support reusing .o files, whether it is actually done or not, it may depend on the toolchain setup, and maybe bugs in the IDE. The Arduino Due toolchain used to rebuild everything everytime but that got fixed.

Excellent suggestion; it explains what I am seeing and why. In the compile output I never see a processor name like atmega328p (no -mcpu flag in the log), so it makes sense to me that it is likely a toolchain issue.

Thanks!
Larry

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.