How to fix PlatformIO mbed error: 'Mutex' does not name a type

Problem:

You are trying to compile your PlatformIO mbed application using Mutexes like

mutex-example.c
Mutex myLock;

but you see an error message like

mutex-error.txt
src\main.cpp:3:1: error: 'Mutex' does not name a type
 Mutex myLock;
 ^~~~~

Solution

Add this line to your platformio.ini:

platformio.ini.snippet
build_flags = -D PIO_FRAMEWORK_MBED_RTOS_PRESENT

This will enable the RTOS features in mbed, including the Mutex.


Check out similar posts by category: Mbed, PlatformIO