Arm Mbed OS support forum

Creating libraries and hiding code

What is the best way to create libraries for use in Mbed Studio without revealing all the source files?

To be specific, I am teaching using Mbed Studio, and for some tasks, I tend to write C++ classes to abstract some of the hardware we use. Later I get them to write their own drivers in C++, so I am particularly keen to not give away solutions.

Therefore, I want them to see the header file and hide implementation file (.cpp). I can’t seem to find a simple way to do this. Any suggestions?

1 Like

Hi Nicholas,

It is a very interesting use-case. One thing that comes to mind is that you can hide any files from explorer using preferences: files.exclude. It is however not perfect as your students can always enable it back. Those files will also still be reachable using C/C++ IntelliSense.

For the browser version of Studio, we are actually implementing also a read-only view for libraries. Unfortunately, it is still not a perfect solution for your use-case as files inside libraries will still be viewable (just not editable).

We will investigate implementing a similar solution as Online Compiler currently has. We rejected this idea in the past but you showed us a valid use-case for it. Thank you. No promises but we may consider having both simple and advanced views when working with libraries.

Arek - Studio team



One option is to build a static library (a binary file with .a extension) using the mbed-cli build tool:

mbed  compile -m TARGET_MCU --library --source [source file]

Although the source code is shared a specific library has to be built for each target (and toolchain).
Then you can distribute the static library (binary file) along with a header file as a library.
If you copy the static library (the header + the binary .a file) to the root directory of your project the compiler is able to find and link it. This is how it works with mbed-cli. Although I haven’t tried that with the Mbed Studio it should be the same.

Best regards, Zoltan

1 Like

Excellent. I will try this today and report back


Thanks for the response. Education is certainly one clear use-case.

I imagine there may also be businesses that might want to provide 3rd party libraries without distributing sources, but I don’t want to speak for others.

Is there a beta for the online version?


1 Like

From an mbed studio terminal, when I try this it says there is a missing dependency “cbor”
Fixing this then breaks Mbed Studio

@arekzaluski Can I install the Mbed CLI in parallel to MBS without one breaking the other?

Yes, you can have mbed-cli installed in parallel with the Mbed Studio.

Below is an example of building a NTPClient library:

Let’s say you have your NTPClient source files (NTPClient.h and NTPClient.cpp) somewhere on your local harddrive and you’d like to build a static library for a NUCLEO_F446RE target using the GCC_ARM toolchain. For that you need to know the path to the mbed-os on your system. Let’s say it is located at ~/src/arm/sys/mbed-os.
To build the library, open a terminal (command) window in the folder containing your library source files and execute the following command

mbed compile -m NUCLEO_F446RE --library --source . --source ~/src/arm/sys/mbed-os

Once the compilation is finished you’ll find a libNTPClient.a file in the NTPClient/NUCLEO_F446RE/GCC_ARM directory.
Keep in mind that this library can be used to build programs only for the NUCLEO_F446RE target and with the mbed-os revision used to build the library.


Ok, I’ll install the CLI tools again and give it a try. I really appreciate you taking the time to answer this.

Hi @noutram,

Yes cbor is a new python dependency required in newest versions of Mbed OS for particular targets. We have added it to 1.3.1 patch release that will be available within the next few days. Until then you can install it in the following way:

  1. Open a built-in terminal in Studio: Menu->Termial->New Terminal
  2. Use pip to install it: pip install cbor
  3. Build your program again

Mbed Studio is shipped with its own python environment. It is completely independent from Python installed on user system. You can fully interact with it from terminal inside Studio.

Arek - Studio team

Hi @noutram,

I can confirm that we are working on the browser version of Studio. We started running a closed beta program for it 2 months ago. We can send you access for it tomorrow if you are interested in trying it out.

Arek - Mbed Studio team

Sure. That would be great

Have you tried this with the 1.3.0 version of MBS? Slightly concerned it will break (again).

We you able to use the Arm compiler (that comes with Mbed Studio) for this?

I’m afraid the Arm Compiler 6 is included (for free) only with the Mbed Studio. So I’m not able to use it with mbed-cli. However, the Mbed Studio is capable to build also with the GCC_ARM toolchain.

Hi @noutram,

Patch release of Mbed Studio 1.3.1 has just been released today. It is adding missing cbor dependency required by latest versions of Mbed OS.

Arek - Mbed Studio team

1 Like

Ok, I’m getting somewhere with 1.3.1 but now it’s throwing out errors about licensing. @arekzaluski any thoughts?

[DEBUG] Errors: Tool: armar [5db06900]
Traceback (most recent call last):
File “c:\git\lib\uop_msb_2\mbed-os\tools\”, line 201, in main
File “c:\git\lib\uop_msb_2\mbed-os\tools\”, line 791, in build_library
toolchain.build_library(objects, build_path, name)
File “c:\git\lib\uop_msb_2\mbed-os\tools\toolchains\”, line 692, in build_library
self.archive(objects, fout)
File “c:\git\lib\uop_msb_2\mbed-os\tools\toolchains\”, line 414, in archive
self.default_cmd([, ‘-r’, lib_path] + param)
File “c:\git\lib\uop_msb_2\mbed-os\tools\toolchains\”, line 830, in default_cmd
raise ToolException(stderr)
tools.utils.ToolException: Error: L9940E: This variant of Arm Compiler is licensed only for use with Mbed Studio
Product: ARM Compiler 6.14 for Mbed Studio
Component: ARM Compiler 6.14
Tool: armar [5db06900]

[mbed] ERROR: “c:\ProgramData\Mbed Studio\mbed-studio-tools\python\python.exe” returned error.
Code: 1
Path: “c:\git\lib\uop_msb_2”
Command: “c:\ProgramData\Mbed Studio\mbed-studio-tools\python\python.exe -u c:\git\lib\uop_msb_2\mbed-os\tools\ -t ARMC6 -m NU
CLEO_F429ZI --source . --source ./mbed-os --build .\BUILD\libraries\uop_msb_2\NUCLEO_F429ZI\ARMC6 -v”


I have a few questions:

  1. How did you get the output above? Is it from Mbed Studio or mbed-cli?
  2. Have you used Mbed CLI from the built-in Mbed Studio terminal or you installed it yourself?
  3. I understand that you used mbed compile --library --source command. Can you let me know the exact syntax you used?

@hudakz is correct. Arm Compiler 6.14 shipped with Studio is restricted to be used:

  • only for Mbed programs
  • only from within of Mbed Studio
    It means that it can’t be used with Mbed CLI installed outside of Studio. It should however work correctly with Mbed CLI shipped with Studio (the one accessible using the built-in terminal).

We will try to reproduce and check this scenario.

Kind Regards,
Arek - Mbed Studio team

I opened a terminal in mbed studio and ran all commands from there.

mbed compile -v -t ARMC6 -m NUCLEO_F429ZI --library --source . --source ./mbed-os

I also tried being more specific

mbed compile -v -t ARMC6 -m NUCLEO_F429ZI --library --source ./mylib.cpp --source ./mbed-os