Static library and mbed_app.json

The content of mbed_app.json is NOT used when you build a static library with the CLI : mbed -compile --library (the question was also raised earlier but not answered How to Use Overrides for Static Library Build?)

There have been a number of articles and responses on this forum and github around static library. I have spent time reading many of them but I have not found the answer.

With the change in MBED-OS 6, where printf has been removed (see the great post Hitchhiker's Guide to Printf in Mbed 6), it seems that the best solution is making a change in mbed_app.json.

As this file is not used when building a static library, can you advise what is the best way now to include printf.

regards,
Paul

Hello Paul,

Until the mbed tool for building static libraries is improved (I hope someone from the mbed team is periodically scanning this forum to get feedback and new ideas from users), one worarkound to utilize a mbed_app.json for building a static library (without modifying the related mbed tool) could be as follows:

  • Add/use the library to/in a simple program (e.g. blinky).
  • Configure the library using the program’s mbed_app.json
  • Because the compiler doesn’t understand/use json files, the mbed build system, based on the mbed_app.json, generates a mbed_conf.h file reflecting the selected configuration options. (This file actually defines macros to be used by the compiler.)
  • After building the program use the mbed_conf.h to create a list of configuration macros where each macro is preceded with -D (or --macro) and a space char.
  • Use the list of such macros to build the stand alone library by passing it to the
    mbed compile --library command.

thanks. I will give it a try
regards,
Paul

Paul –

From what I understand, you want to configure serial/printf and then create a static library with this configuration that can be reused at another time, is that right?

What about the case where the user doesn’t want serial/printf or is using different ports or even is reimplementing a FileHandle to print on an LCD screen?

What are you using serial/printf for in your library? If it’s debug, maybe mbed-trace would be more suitable.

I might be missing something, so please correct me if I’m wrong.

Hi, thanks for the fast response.

MBED-OS is used on the Sparkfun Artemis/Apollo3 boards. MBED-OS is the backbone and the static library is included in the Arduino IDE build process to create the binary to upload to the board. The created sketches/programs are depending on MBED-OS for a large number of activities. As such it is using the MBED-OS for printf statement in the different sketches/programs.

regards,
Paul

Makes sense then.