Error: rtos.h no such file

Hi, I have been trying to compile this code:

And I always get this error:
rtos.h no such file

But, it compiles successfully and the code works. So, why do I get it?

What is in your platformio.ini file. You could be compiling for more than one platform and it’s failing on the one you aren’t using.

Hi, I’m only compiling the code in one platform, my platformio.ini file is:

[env:nucleo_l152re]
platform = ststm32
framework = mbed
board = nucleo_l152re

I have this problem, and it’s a new problem. I.e. I have a project that compiled previously and now doesn’t.

I think that’s because the rtos folder used to be on the include path, and isn’t any more, but including <rtos/rtos.h> doesn’t work because then you get mbed_rtx_conf.h: No such file or directory which is in rtos/rtx5.

That seems to be that in mbed 5, you don’t #include <rtos.h> any more, you just set a build flag in your project:

build_flags = -DPIO_FRAMEWORK_MBED_PRESENT

Then you can use RTOS features.

I didn’t get the build flags quite right above:

[env:nucleo_f411re]
platform = ststm32
framework = mbed
board = nucleo_f411re
upload_port = /media/david/NODE_F411RE
build_flags = -std=gnu++14 -D PIO_FRAMEWORK_MBED_RTOS_PRESENT

Builds, but then fails to link:

/home/david/.platformio/packages/toolchain-gccarmnoneeabi/bin/…/lib/gcc/arm-none-eabi/6.3.1/…/…/…/…/arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/softfp/crt0.o: In function _start': (.text+0x4a): undefined reference to__wrap_main’
.pioenvs/nucleo_f411re/FrameworkMbedCore/drivers/Serial.o: In function mbed::Serial::lock()': Serial.cpp:(.text._ZN4mbed6Serial4lockEv+0x6): undefined reference tortos::Mutex::lock(unsigned long)’
.pioenvs/nucleo_f411re/FrameworkMbedCore/drivers/Serial.o: In function mbed::Serial::unlock()': Serial.cpp:(.text._ZN4mbed6Serial6unlockEv+0x2): undefined reference tortos::Mutex::unlock()’
.pioenvs/nucleo_f411re/FrameworkMbedCore/drivers/Serial.o: In function mbed::Serial::Serial(PinName, PinName, int)': Serial.cpp:(.text._ZN4mbed6SerialC2E7PinNameS1_i+0x2c): undefined reference tortos::Mutex::Mutex()’
.pioenvs/nucleo_f411re/FrameworkMbedCore/drivers/Serial.o: In function mbed::Serial::~Serial()': Serial.cpp:(.text._ZN4mbed6SerialD2Ev[_ZN4mbed6SerialD5Ev]+0x1c): undefined reference tortos::Mutex::~Mutex()’
.pioenvs/nucleo_f411re/FrameworkMbedCore/platform/FileBase.o: In function SingletonPtr<rtos::Mutex>::get()': FileBase.cpp:(.text._ZN12SingletonPtrIN4rtos5MutexEE3getEv[_ZN12SingletonPtrIN4rtos5MutexEE3getEv]+0x10): undefined reference toosMutexAcquire’
FileBase.cpp:(.text._ZN12SingletonPtrIN4rtos5MutexEE3getEv[_ZN12SingletonPtrIN4rtos5MutexEE3getEv]+0x1e): undefined reference to rtos::Mutex::Mutex()' FileBase.cpp:(.text._ZN12SingletonPtrIN4rtos5MutexEE3getEv[_ZN12SingletonPtrIN4rtos5MutexEE3getEv]+0x26): undefined reference toosMutexRelease’
FileBase.cpp:(.text._ZN12SingletonPtrIN4rtos5MutexEE3getEv[_ZN12SingletonPtrIN4rtos5MutexEE3getEv]+0x30): undefined reference to singleton_mutex_id' .pioenvs/nucleo_f411re/FrameworkMbedCore/platform/FileBase.o: In functionmbed::FileBase::FileBase(char const*, mbed::PathType)’:
FileBase.cpp:(.text._ZN4mbed8FileBaseC2EPKcNS_8PathTypeE+0x1c): undefined reference to rtos::Mutex::lock(unsigned long)' FileBase.cpp:(.text._ZN4mbed8FileBaseC2EPKcNS_8PathTypeE+0x30): undefined reference tortos::Mutex::unlock()’
.pioenvs/nucleo_f411re/FrameworkMbedCore/platform/FileBase.o: In function mbed::FileBase::~FileBase()': FileBase.cpp:(.text._ZN4mbed8FileBaseD2Ev+0x12): undefined reference tortos::Mutex::lock(unsigned long)‘
FileBase.cpp:(.text._ZN4mbed8FileBaseD2Ev+0x2c): undefined reference to rtos::Mutex::unlock()' .pioenvs/nucleo_f411re/FrameworkMbedCore/platform/FileBase.o: In functionmbed::FileBase::lookup(char const*, unsigned int)’:
FileBase.cpp:(.text._ZN4mbed8FileBase6lookupEPKcj+0x10): undefined reference to rtos::Mutex::lock(unsigned long)' FileBase.cpp:(.text._ZN4mbed8FileBase6lookupEPKcj+0x38): undefined reference tortos::Mutex::unlock()’
.pioenvs/nucleo_f411re/FrameworkMbedCore/platform/mbed_retarget.o: In function mbed::remove_filehandle(mbed::FileHandle*)': mbed_retarget.cpp:(.text._ZN4mbed17remove_filehandleEPNS_10FileHandleE+0xe): undefined reference tortos::Mutex::lock(unsigned long)‘
mbed_retarget.cpp:(.text._ZN4mbed17remove_filehandleEPNS_10FileHandleE+0x34): undefined reference to rtos::Mutex::unlock()' .pioenvs/nucleo_f411re/FrameworkMbedCore/platform/mbed_retarget.o: In function_open’:
mbed_retarget.cpp:(.text._open+0x4e): undefined reference to rtos::Mutex::lock(unsigned long)' mbed_retarget.cpp:(.text._open+0x72): undefined reference tortos::Mutex::unlock()‘
mbed_retarget.cpp:(.text._open+0xf2): undefined reference to rtos::Mutex::unlock()' .pioenvs/nucleo_f411re/FrameworkMbedCore/platform/mbed_wait_api_rtos.o: In functionwait_us’:
mbed_wait_api_rtos.cpp:(.text.wait_us+0x2a): undefined reference to rtos::Thread::wait(unsigned long)' .pioenvs/nucleo_f411re/src/main.o: In functionslip::SlipOutput::~SlipOutput()’:
main.cpp:(.text._ZN4slip10SlipOutputD2Ev[_ZN4slip10SlipOutputD5Ev]+0xa): undefined reference to rtos::Mutex::~Mutex()' .pioenvs/nucleo_f411re/src/main.o: In functionServos<4u>::moveStep()’:
main.cpp:(.text._ZN6ServosILj4EE8moveStepEv[_ZN6ServosILj4EE8moveStepEv]+0x48): undefined reference to rtos::Thread::signal_set(long)' .pioenvs/nucleo_f411re/src/main.o: In functionServos<4u>::statusSender()’:
main.cpp:(.text._ZN6ServosILj4EE12statusSenderEv[_ZN6ServosILj4EE12statusSenderEv]+0x14): undefined reference to rtos::Thread::signal_wait(long, unsigned long)' .pioenvs/nucleo_f411re/src/main.o: In functionServos<4u>::~Servos()’:
main.cpp:(.text._ZN6ServosILj4EED2Ev[_ZN6ServosILj4EED5Ev]+0x6): undefined reference to rtos::Thread::~Thread()' .pioenvs/nucleo_f411re/src/main.o: In function_GLOBAL__sub_I_serial’:
main.cpp:(.text.startup._GLOBAL__sub_I_serial+0x58): undefined reference to rtos::Mutex::Mutex()' main.cpp:(.text.startup._GLOBAL__sub_I_serial+0xde): undefined reference tortos::Semaphore::Semaphore(long)‘
main.cpp:(.text.startup._GLOBAL__sub_I_serial+0xe6): undefined reference to rtos::Mutex::Mutex()' main.cpp:(.text.startup._GLOBAL__sub_I_serial+0xf8): undefined reference tortos::Thread::constructor(osPriority_t, unsigned long, unsigned char*, char const*)‘
main.cpp:(.text.startup._GLOBAL__sub_I_serial+0x132): undefined reference to rtos::Thread::start(mbed::Callback<void ()>)' main.cpp:(.text.startup._GLOBAL__sub_I_serial+0x1c8): undefined reference tovtable for rtos::Thread’
.pioenvs/nucleo_f411re/lib/libcanonical-sexps.a(SlipOutput.o): In function slip::SlipOutput::begin()': SlipOutput.cpp:(.text._ZN4slip10SlipOutput5beginEv+0xa): undefined reference tortos::Mutex::lock(unsigned long)’
.pioenvs/nucleo_f411re/lib/libcanonical-sexps.a(SlipOutput.o): In function slip::SlipOutput::end()': SlipOutput.cpp:(.text._ZN4slip10SlipOutput3endEv+0x12): undefined reference tortos::Mutex::unlock()’

I’m having the exact same issue as @davidji. It builds, but gives errors on linking.

Are there any updates on this?

Could you share a test source code to reproduce this issue?

You need to make sure that the build_flags is correct, according to the guide, (mbed configuration)

That means using the following build_flags as appropriate:

  • -D PIO_FRAMEWORK_MBED_RTOS_PRESENT
  • -D PIO_FRAMEWORK_MBED_EVENTS_PRESENT
  • -D PIO_FRAMEWORK_MBED_FILESYSTEM_PRESENT

AND…

you still need to #include "rtos.h", otherwise, the dependency finder will not include the RTOS lib. Normally, mbed does not make you explicitly declare rtos.h, bit PlatformIO extracts it as a separate library behind the scenes, so you need to declare it.

If you do it right, you should get output in the console that shows mbed-rtos in the Library Dependency Graph