6 years ago.

MBED CLI command for linking to pre-compiled libraries?

I'm using the MBED CLI. I have a user program that depends on the mbed-os. I want to be able to pre-compile the mbed-os source into a library archive file and link to it to build my user program. I was able to use:

mbed compile ... --library --source=mbed-os --build=mbed-os-build

This does generate a library archive file (libmbed-os.a) in the mbed-os-build directory. I'm not sure what command to use to link to the library archive file. The MBED CLI help documents don't describe how to accomplish this. It appears that a user program can only be built with mbed-os object files (*.o). Can anyone help out with my desired workflow?

I should add that this is a general workflow that I would like to be able to achieve with any library, not just mbed-os. For example, if I add my own library or pull in another library, I would like to be able to link those into my user application program from one location under my project root directory. It seems that the workflow assumed by MBED CLI is to add libraries to each user application. So, if I have 5 user application programs, I have 5 separate copies of every library dependency (eg, 5 mbed-os, 5 C12832, etc). Even the command I show above creates a new mbed-os directory under mbed-os-build. The entire mbed-os hierarchy is copied to the new directory under mbed-os-build, then the compiler generates each *.o in that hierarchy during the build process. If I'm misunderstanding how this works, I'll be happy to hear advice about how to achieve my desired workflow. I have read the MBED CLI doc's a number of times, but I might be missing something.

12 Nov 2018: I've edited the wording of my question in the hope that someone will post an answer.

No replies since I asked this question 6 days ago. Can anyone from the Mbed dev team provide any help with this?

posted by David G 08 Nov 2018

1 Answer

6 years ago.

this example is working: https://github.com/ARMmbed/mbed-cli#compiling-static-libraries In the example, the option no-archive is used and it will be linked still against the object files. But the mbed-os files are only compiled once to the mbed-os-build.

I have put this dir on the same level as mbed-os and app1...app n. I tried also to omit the no-archive option and deleted all .o and .d files in the mbed-os-build. That was working also, so the mbed compile is using the archive file. The resulting binary was even 1496 bytes smaller, but the build statistics shows size '0' for mbed-os. So it may be better to use the no-archive option.

The magic seems to be in the 'source' option for the compile, it uses also the header and object and archive files. This should be mentioned in the mbed-cli documentation.

Sorry for the late comment, but I gave up on checking this post due to lack of replies.

I see what you're saying. The documentation is not very clear on that kind of workflow. Even the example is confusing, because it looks like it is leaving out changes in the current working directory. That was part of my confusion.

While it may work, it hides too much from the end-user. I like to have visibility into the general location of my targets/dependencies. I don't like to see redundant copies of large directories (mbed-os!!!). It also makes working with Git confusing. mbed-cli seems to mimic some Git behavior. I'm never sure what I need to track or not track. That is another area where the documentation is lacking. I didn't even want to install Mecurial, but I was forced to in order to use mbed-cli. Sorry, but I just don't understand that workflow. I guess I'm too old-school.

In the meantime, I have migrated most of my development away from mbed-cli and towards using standard GNU Make/Makefile's. It was a bit of work, but it makes this whole process so much more flexible and visible. For those who've never used "make", you really are missing something. I can now easily build "all", "objects", "lib", "foo.o", etc. I can now put library archives into a common folder and link to them as desired. I use Git to track exactly what I want to track.

posted by David G 01 Dec 2018