Vscode mbed.h not found

I am trying to use visual studio code with platformio on windows 10. But I’ve come across an error which I could find any solution to. I am aware about a fix for it but this only worked on macOS(?).
I get an error whenever I try to include <mbed.h>, I can include other libraries like <stdlib.h> and it does compile when I don’t include <mbed.h>. I do have mbed installed. the only thing that I could think of is that I have my project on my D: drive and the mbed headers are on my C: drive.

Here is the error message I get:

{
“resource”: “/d:/PlatformIOProjects/test6/d:/PlatformIOProjects/test6/src/main.cpp”,
“owner”: “cpptools”,
“severity”: 8,
“message”: “mbed.h: No such file or directory”,
“source”: “gcc”,
“startLineNumber”: 1,
“startColumn”: 10,
“endLineNumber”: 1,
“endColumn”: 10
}


as you can see in the screenshot I have made a new project and I have not written any code yet. but it still gives me the error.

if this question has been answered already I would like to know the answer and where to find it.

I had a similar issue with a recent install of VS Code/PIO. It sounds like you have confirmed the existence of the mbed.h header. If you have not, I noticed that the first build will actually download additional packages that the PIO install did not. Worth a try!

1 Like

And how do I do that? I’m guessing that you mean building my project but I can’t build it cause it gives me an compile error.

Which exact error?

Does creating the project on C:\ make the errors go away?

You can see the error in the screenshot, the message says:
#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (D:\PlatformIOProjects\test6\src\main.cpp).

cannot open source file "mbed.h"

I didn’t try this initially because I have little disk space left on my C:/ drive. I just tried it and it still gives the exact same error.

Oh I thought you also had errors compiling, not just in the VSCode intellisense.

What’s the content of your .vscode/c_cpp_properties.json? (pastebin or here)

My C:\Users\me\ .platformio\packages directory has 11 directories. I had 4 or 5 before my first build.
The framework-mbed directory contains mbed.h
I also have a framework-mbed@5.51401.200110 directory
My problem was that I had to:
a. Fire off a build to get the remaining packages installed
b. Rebuild the IntelliSense Index (last PIO Project Task)

Since you are constrained for space on your C: did you pickup all 11 packages?
Do you in fact have a mbed.h in your framework-mbed directory? I think [maxgerhardt] is alluding to verifying that your include path points to the correct location.

“includePath”: [
“c:/Users/terry/Documents/PlatformIO/Projects/Test02/include”,
“c:/Users/terry/Documents/PlatformIO/Projects/Test02/src”,
“C:/Users/terry/.platformio/packages/framework-mbed/cmsis/TARGET_CORTEX_M”,
"C:/Users/terry/.platformio/packages/framework-mbed",

2 Likes

:information_source: Terminology pitstop. :wink:

An include error in the ‘Problems’ tab is NOT a compile error. In fact, none of the messages in the problems tabs are ‘compile errors’. They are warnings from the VSCode C++ Intellisense extension, which can sometimes be caused because you have not yet compiled / built your project, hence PlatformIO hasn’t downloaded all the stuff yet needed to actually compile your project, thus the error might be valid at that time, but will go away upon actually compiling the code. Compile errors are those that you’ll see, well, when you actually try to compile the code!

Hence what TerryMcP63 experienced, as PlatformIO will only download packages as needed. To do otherwise would result in it downloading several gigabytes of toolchains and platform files, when you might only be using one or two.

2 Likes
{
"configurations": [
    {
        "name": "!!! WARNING !!! AUTO-GENERATED FILE, PLEASE DO NOT MODIFY IT AND USE https://docs.platformio.org/page/projectconf/section_env_build.html#build-flags"
    },
    {
        "name": "Win32",
        "includePath": [
            "D:/PlatformIOProjects/test6/include",
            "D:/PlatformIOProjects/test6/src",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/cmsis/TARGET_CORTEX_M",
            "C:/Users/Thomas/.platformio/packages/framework-mbed",
            "D:/PlatformIOProjects/test6/.pio/build/disco_f051r8",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/drivers",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/drivers/internal",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/events",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/events/internal",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/hal",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/hal/storage_abstraction",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/hal/usb",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/platform",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/platform/cxxsupport",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/platform/internal",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/platform/source",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/platform/source/TARGET_CORTEX_M",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/platform/source/minimal-printf",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/targets/TARGET_STM",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/targets/TARGET_STM/TARGET_STM32F0",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/targets/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/targets/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/device",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/targets/TARGET_STM/TARGET_STM32F0/device",
            "C:/Users/Thomas/.platformio/lib/cmsis-core_ID1237/source",
            "C:/Users/Thomas/.platformio/lib/cmsis-core_ID1237",
            "C:/Users/Thomas/.platformio/lib/cmsis-core_ID1237/cmsis-core",
            "C:/Users/Thomas/.platformio/lib/compiler-polyfill_ID1239",
            "C:/Users/Thomas/.platformio/lib/core-util_ID1236/source",
            "C:/Users/Thomas/.platformio/lib/core-util_ID1236",
            "C:/Users/Thomas/.platformio/lib/dlmalloc_ID1235/source",
            "C:/Users/Thomas/.platformio/lib/dlmalloc_ID1235",
            "C:/Users/Thomas/.platformio/lib/greentea-client_ID963/source",
            "C:/Users/Thomas/.platformio/lib/greentea-client_ID963",
            "C:/Users/Thomas/.platformio/lib/mbed-drivers_ID962/source",
            "C:/Users/Thomas/.platformio/lib/mbed-drivers_ID962",
            "C:/Users/Thomas/.platformio/lib/mbed-drivers_ID962/mbed",
            "C:/Users/Thomas/.platformio/lib/mbed-hal_ID1004/source",
            "C:/Users/Thomas/.platformio/lib/mbed-hal_ID1004",
            "C:/Users/Thomas/.platformio/lib/mbed-hal_ID1004/mbed-hal",
            "C:/Users/Thomas/.platformio/lib/minar-platform_ID1240",
            "C:/Users/Thomas/.platformio/lib/minar_ID1238/source",
            "C:/Users/Thomas/.platformio/lib/minar_ID1238",
            "C:/Users/Thomas/.platformio/lib/ualloc_ID1234/source",
            "C:/Users/Thomas/.platformio/lib/ualloc_ID1234",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/dsp",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/dsp/cmsis_dsp",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/dsp/dsp",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/rpc",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBDevice",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBDevice/USBAudio",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBDevice/USBDevice",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBDevice/USBHID",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBDevice/USBMIDI",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBDevice/USBMSD",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBDevice/USBSerial",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBDevice/targets/TARGET_STM",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBHost",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBHost/USBHost",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBHost/USBHost3GModule",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBHost/USBHostHID",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBHost/USBHostHub",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBHost/USBHostMIDI",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBHost/USBHostMSD",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBHost/USBHostSerial",
            "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBHost/targets/TARGET_STM",
            "C:/Users/Thomas/.platformio/packages/tool-unity",
            ""
        ],
        "browse": {
            "limitSymbolsToIncludedHeaders": true,
            "path": [
                "D:/PlatformIOProjects/test6/include",
                "D:/PlatformIOProjects/test6/src",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/cmsis/TARGET_CORTEX_M",
                "C:/Users/Thomas/.platformio/packages/framework-mbed",
                "D:/PlatformIOProjects/test6/.pio/build/disco_f051r8",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/drivers",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/drivers/internal",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/events",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/events/internal",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/hal",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/hal/storage_abstraction",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/hal/usb",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/platform",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/platform/cxxsupport",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/platform/internal",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/platform/source",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/platform/source/TARGET_CORTEX_M",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/platform/source/minimal-printf",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/targets/TARGET_STM",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/targets/TARGET_STM/TARGET_STM32F0",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/targets/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/targets/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/device",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/targets/TARGET_STM/TARGET_STM32F0/device",
                "C:/Users/Thomas/.platformio/lib/cmsis-core_ID1237/source",
                "C:/Users/Thomas/.platformio/lib/cmsis-core_ID1237",
                "C:/Users/Thomas/.platformio/lib/cmsis-core_ID1237/cmsis-core",
                "C:/Users/Thomas/.platformio/lib/compiler-polyfill_ID1239",
                "C:/Users/Thomas/.platformio/lib/core-util_ID1236/source",
                "C:/Users/Thomas/.platformio/lib/core-util_ID1236",
                "C:/Users/Thomas/.platformio/lib/dlmalloc_ID1235/source",
                "C:/Users/Thomas/.platformio/lib/dlmalloc_ID1235",
                "C:/Users/Thomas/.platformio/lib/greentea-client_ID963/source",
                "C:/Users/Thomas/.platformio/lib/greentea-client_ID963",
                "C:/Users/Thomas/.platformio/lib/mbed-drivers_ID962/source",
                "C:/Users/Thomas/.platformio/lib/mbed-drivers_ID962",
                "C:/Users/Thomas/.platformio/lib/mbed-drivers_ID962/mbed",
                "C:/Users/Thomas/.platformio/lib/mbed-hal_ID1004/source",
                "C:/Users/Thomas/.platformio/lib/mbed-hal_ID1004",
                "C:/Users/Thomas/.platformio/lib/mbed-hal_ID1004/mbed-hal",
                "C:/Users/Thomas/.platformio/lib/minar-platform_ID1240",
                "C:/Users/Thomas/.platformio/lib/minar_ID1238/source",
                "C:/Users/Thomas/.platformio/lib/minar_ID1238",
                "C:/Users/Thomas/.platformio/lib/ualloc_ID1234/source",
                "C:/Users/Thomas/.platformio/lib/ualloc_ID1234",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/dsp",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/dsp/cmsis_dsp",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/dsp/dsp",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/rpc",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBDevice",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBDevice/USBAudio",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBDevice/USBDevice",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBDevice/USBHID",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBDevice/USBMIDI",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBDevice/USBMSD",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBDevice/USBSerial",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBDevice/targets/TARGET_STM",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBHost",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBHost/USBHost",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBHost/USBHost3GModule",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBHost/USBHostHID",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBHost/USBHostHub",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBHost/USBHostMIDI",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBHost/USBHostMSD",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBHost/USBHostSerial",
                "C:/Users/Thomas/.platformio/packages/framework-mbed/features/unsupported/USBHost/targets/TARGET_STM",
                "C:/Users/Thomas/.platformio/packages/tool-unity",
                ""
            ]
        },
        "defines": [
            "PLATFORMIO=40200",
            "STM32F051x8",
            "ARM_MATH_CM0",
            "CMSIS_VECTAB_VIRTUAL",
            "CMSIS_VECTAB_VIRTUAL_HEADER_FILE=\"cmsis_nvic.h\"",
            "COMPONENT_NSPE=1",
            "COMPONENT_PSA_SRV_EMUL=1",
            "COMPONENT_PSA_SRV_IMPL=1",
            "DEVICE_ANALOGIN=1",
            "DEVICE_CRC=1",
            "DEVICE_I2C=1",
            "DEVICE_I2CSLAVE=1",
            "DEVICE_I2C_ASYNCH=1",
            "DEVICE_INTERRUPTIN=1",
            "DEVICE_MPU=1",
            "DEVICE_PORTIN=1",
            "DEVICE_PORTINOUT=1",
            "DEVICE_PORTOUT=1",
            "DEVICE_PWMOUT=1",
            "DEVICE_RESET_REASON=1",
            "DEVICE_RTC=1",
            "DEVICE_SERIAL=1",
            "DEVICE_SERIAL_FC=1",
            "DEVICE_SLEEP=1",
            "DEVICE_SPI=1",
            "DEVICE_SPISLAVE=1",
            "DEVICE_SPI_ASYNCH=1",
            "DEVICE_STDIO_MESSAGES=1",
            "DEVICE_USTICKER=1",
            "DEVICE_WATCHDOG=1",
            "TARGET_CORTEX",
            "TARGET_CORTEX_M",
            "TARGET_DISCO_F051R8",
            "TARGET_FAMILY_STM32",
            "TARGET_LIKE_CORTEX_M0",
            "TARGET_LIKE_MBED",
            "TARGET_M0",
            "TARGET_NAME=DISCO_F051R8",
            "TARGET_RELEASE",
            "TARGET_STM",
            "TARGET_STM32F0",
            "TARGET_STM32F051",
            "TARGET_STM32F051R8",
            "TOOLCHAIN_GCC",
            "TOOLCHAIN_GCC_ARM",
            "TRANSACTION_QUEUE_SIZE_SPI=2",
            "USE_FULL_LL_DRIVER",
            "USE_HAL_DRIVER",
            "__CMSIS_RTOS",
            "__CORTEX_M0",
            "__MBED_CMSIS_RTOS_CM",
            "__MBED__=1",
            ""
        ],
        "intelliSenseMode": "clang-x64",
        "cppStandard": "c++14",
        "compilerPath": "C:/Users/Thomas/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc.exe",
        "compilerArgs": [
            "-mcpu=cortex-m0",
            "-mthumb",
            "-include",
            ""
        ]
    }
],
"version": 4

}

I’m very sorry about the confusing terminology, I thought that every warning and error was a compile error. I did try to compile the empty test project but it gives the exact same error or warning.

So what I think I’m getting is that I don’t have all the needed packages. and I need to compile to get those(?) but I can’t get my code to compile so I’m still not sure how to solve my problem.

Also many thanks for the extra terminology pitstop!

1 Like

Okay, So I did some more research with the hint of installing mbed. And I feel like an idiot. I overlook that there where more “tabs”(?) in the PIO home page. and I found out that I didn’t install the STM32 framework. which (probably obviously) comes with the mbed.h library.

In any case, I didn’t get the warnings I got before, but now I think I truly have a compile error. Now that I have (I think) everything. when I start the build (with the button, before I used crtl+shif+b). I get this in the terminal.

Processing disco_f051r8 (platform: ststm32; board: disco_f051r8; framework: mbed)
------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/disco_f051r8.html
PLATFORM: ST STM32 6.0.0 > ST STM32F0DISCOVERY
HARDWARE: STM32F051R8T6 48MHz, 8KB RAM, 64KB Flash
DEBUG: Current (stlink) On-board (stlink) External (blackmagic, jlink)
PACKAGES:
 - framework-mbed 5.51401.200110 (5.14.1)
 - toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)
Collecting mbed sources...
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 14 compatible libraries
Scanning dependencies...
TypeError: string indices must be integers:
  File "C:\users\thomas\.platformio\penv\lib\site-packages\platformio\builder\main.py", line 156:
    env.SConscript("$BUILD_SCRIPT")
  File "C:\Users\Thomas\.platformio\packages\tool-scons\script\..\engine\SCons\Script\SConscript.py", line 541:
    return _SConscript(self.fs, *files, **subst_kw)
  File "C:\Users\Thomas\.platformio\packages\tool-scons\script\..\engine\SCons\Script\SConscript.py", line 250:
    exec _file_ in call_stack[-1].globals
  File "C:\users\thomas\.platformio\platforms\ststm32\builder\main.py", line 98:
    target_elf = env.BuildProgram()
  File "C:\Users\Thomas\.platformio\packages\tool-scons\script\..\engine\SCons\Environment.py", line 224:
    return self.method(*nargs, **kwargs)
  File "C:\users\thomas\.platformio\penv\lib\site-packages\platformio\builder\tools\platformio.py", line 62:
    env.ProcessProjectDeps()
  File "C:\Users\Thomas\.platformio\packages\tool-scons\script\..\engine\SCons\Environment.py", line 224:
    return self.method(*nargs, **kwargs)
  File "C:\users\thomas\.platformio\penv\lib\site-packages\platformio\builder\tools\platformio.py", line 131:
    project_lib_builder = env.ConfigureProjectLibBuilder()
  File "C:\Users\Thomas\.platformio\packages\tool-scons\script\..\engine\SCons\Environment.py", line 224:
    return self.method(*nargs, **kwargs)
  File "C:\users\thomas\.platformio\penv\lib\site-packages\platformio\builder\tools\piolib.py", line 1035:
    project.search_deps_recursive()
  File "C:\users\thomas\.platformio\penv\lib\site-packages\platformio\builder\tools\piolib.py", line 423:
    self.depend_recursive(lb, lb_search_files)
  File "C:\users\thomas\.platformio\penv\lib\site-packages\platformio\builder\tools\piolib.py", line 399:
    lb.search_deps_recursive(search_files)
  File "C:\users\thomas\.platformio\penv\lib\site-packages\platformio\builder\tools\piolib.py", line 404:
    self.process_dependencies()
  File "C:\users\thomas\.platformio\penv\lib\site-packages\platformio\builder\tools\piolib.py", line 279:
    if item["name"] != lb.name:
========================================================= [FAILED] Took 13.11 seconds =========================================================
The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.

I don’t quite get why it would give me a typeError. I installed python just incase that would fix it but it didn’t. The only thing I can think of is that I accedentally srewed something up in the library’s but I kind of just installed it. So I’m not sure about that.

Edit: Apperantly is a bug that is being worked on. TypeError: string indices must be integers: · Issue #3400 · platformio/platformio-core · GitHub

1 Like