Cannot build SD card example mbed os 6

Hello, I recently installed mbed-cli 2 and managed to compile my first projects with mbed os 6.8. Now I’m trying to build this example for a NUCLEO_F103RB target with an external SD card module but the compiler CMake is failing to find “SDBlockDevice.h” as shown below:

FAILED: CMakeFiles/sd_card.dir/main.cpp.obj 
... main.cpp:7:10: fatal error: SDBlockDevice.h: No such file or directory
7 | #include "SDBlockDevice.h"
    |          ^~~~~~~~~~~~~~~~~
compilation terminated.

My mbed_app.json file contains the following:

    "target_overrides": {
        "NUCLEO_F103RB": {
            "platform.stdio-baud-rate": 9600,
            "target.features_add": ["STORAGE"],
            "target.components_add": ["SD"]

And I verified that STORAGE and SD components are in the mbed_config.cmake file.

I just created a new project with mbed-tools new .\<folder name> and pasted the example in the main.cpp file. I don’t know how to solve this issue, the solutions are found only refer to the mbed_app.json file which I have already modified. Any help is welcomed.

UPDATE: I have tried using mbed-cli 1 and mbed studio, but got the same error… Is it really that complicated to build an example project?


It should be fine, if your mbed_app.json does not have requires block.
If you have additional item such as bare-metal, you also need to add sd in your mbed_app.json.

    "requires": [


Hi, thank you for your answer. I’m not intending to use the bare-metal profile, I was looking for the full Mbed OS 6 capabilities. After trying many different combinations none of them worked:

Importing a Github example:

> mbed-tools import mbed-os-example-sd-driver
> mbed-tools compile -m K64F -t GCC_ARM

CMake Error at CMakeLists.txt:18 (mbed_set_mbed_target_linker_script):
Unknown CMake command "mbed_set_mbed_target_linker_script".

Creating a new project and compiling the default code:

> mbed-tools new .\SD_card
> mbed-tools -t GCC_ARM -m NUCLEO_F103RB
"Build succeeds"

Adding "target.features_add" : ["STORAGE"], "target.components_add": ["SD"] and copying the main.cpp code from here :

> mbed-tools -t GCC_ARM -m NUCLEO_F103RB
main.cpp:2:10: fatal error: SDBlockDevice.h: No such file or directory

Trying to add "requires" : ["sd"], or "requires":["bare-metal", "sd"] with the same code:

> mbed-tools -t GCC_ARM -m NUCLEO_F103RB
CThunkBase.h:59:43: error: 'MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX' was not 
declared in this scope
static const CThunkEntry _thunk_table[MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX];
"Among other errors"

I don’t know what else to try… Is what you suggested listed in somewhere in the documentation?

The issue I’m experiencing seems to be related to any additional “component” not only to SDBlockDevice.h.


I’m not intending to use the bare-metal profile, I was looking for the full Mbed OS 6 capabilities.

Ah, sorry about this. I was testing this with Mbed CLI 1, not 2. Please forget about the bare-metal stuff.
For CLI 2 (mbed-tools) build, you need to have proper link library description in the CMakeLists.txt file in your project. So, you can add…



Thank you so much! That solved the issue and project was built without warnings and errors. In fact my original CMakeLists.txt file contained only:

target_link_libraries(${APP_TARGET} mbed-os)

About the bare-metal profile it is still good to know, it might be useful for other projects!

Just a couple of questions:

  • Is there any difference in using Mbed CLI 1 or Mbed CL2 for the average user? I tried the first version as well but wanted to stick to the latest one.
  • What is the purpose of the PRIVATE label? Is there documentation for that and in general for everything that was discussed in this thread? I’ll be happy to read it but I couldn’t find it.

Thank you again for you help!