Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
2 years, 8 months 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.
2 years, 8 months 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.