arduino-cli
arduino-cli copied to clipboard
Build library to .a file, use multiple sketches with .a file
Moved here from this forum post.
Not sure if this is my lack of understanding, a [documentation] bug report or an enhancement request.
I would like to ask arduino-cli to:
a) build my library, for a given architecture, to a .a file,
b) build sketch x, linking it with the above .a file.
c) build sketch y, linking it with the above .a file.
I can see that the dot_a_linkage directive in the library file metadata will tell arduino-cli to build the library to an intermediate .a file but I can't see how I would tell arduino-cli to just build the library for me, so not build a whole sketch but just build the library. The reason I would like to do this as a distinct step is to make sure that the library is built in "its own" way, any conditional compilation is decided by the library builder, not by some random application.
And then, of course, how would I tell it to compile and then link a given sketch using that .a file rather than building the library from source (though I guess that might be automatic?)?
I understand that I could do all of this manually (e.g. using an empty .ino file for (a) and then copying the resulting library .a file somewhere or other), what I'm asking is whether arduino-cli can be told to perform these steps by itself; it is a perfectly normal/logical build operation to perform and it looks as though arduino-cli should be able to do it, I just can't figure out how.
I suppose that what I really want is a lib command which compiles the library for the given platform. Job done.
Environment
- CLI version
arduino-cli alpha Version: 0.19.0 Commit: 56419ecd Date: 2021-09-02T14:47:35Z - OS and platform: Windows 10 Pro 20H2
[Deleted comment about not being able to do this manually: I realised that the --libraries parameter to compile should be to the directory above the library file, so I was specifying:
--libraries c:\temp\_jenkins_work\libraries\ubxlib --libraries c:\temp\_jenkins_work\libraries\ubxlib_test
...which causes arduino-cli to dump the .o files for both libraries into the src directory of the build output and then NOT package them into .a files. If instead I specify:
--libraries c:\temp\_jenkins_work\libraries
...then it puts the .o files into library-named sub-directories of the build output (i.e. ubxlib and ubxlib_test) and does correctly package the .o files into .a files first].
It might be worth updating your excellent command-line help to say that the --libraries directive will recurse so only the root needs to be specified.
So I can do it myself but a dummy .ino file and a Python script are required to perform the build and then copy the .a file into the correct place, whereas I'd have thought arduino-cli could simply JFDI...?
Interesting solution. In my case, I am using Cmake to use the arduino SDK to build the library and copy the archive file (.a).
I think this would be a nice feature for developers of Arduino libraries ;)