How to get Standard Libraries in Visual Studio Code & PlatformIO?

Hello everyone. Happy New Year 2020!

I have been using Visual Studio Code for development on my Arduino Uno. The reason being, is that you can get nice syntax highlighting, linting, and other fancy IDE features which makes programming in C++ more efficient.

Visual Studio Code has this rather impressive extension called ‘PlatformIO’. It is basically an all-in-one solution for development with different micro-controllers, including Arduinos. Upon creating a new project, it will automatically install the needed drivers and standard arduino libraries for you, as well as generate a configuration file that is needed to compile and upload the code.

The only problem I have have with PlatformIO, is that it doesn’t seem to detect the standard c++ library. I’ll #include vectorfor example, and it will say that the header files cannot be found. This is only a unique issue to the Arduino workspace environment. You can generate a normal workspace in VScode and use all the standard C++ libraries without a problem.

So I know that C++ libraries are installed. I can even see it under the installed extensions list in VScode. It seems that the PlatformIO configuration doesn’t know how to locate it and I’m not exactly sure how to configure it manually.

There seems to be build options according to PlatformIO’s documentation, you just need to edit the platformio.ini configuration file. The problem is, the default configuration file doesn’t actually generate any default build options within it, and I am not exactly sure what compiler it is using.

Does it use the MSVC compiler or the GCC compiler? And does it makes a difference for building Arduino compatible code?

Additionally, I don’t know where VScode installs whatever C++ library it is using, so I’m not really sure how to tell PlatformIO where to look.

Yesterday, I spent some time taking the C++ library header files from a MinGW installation and copying them to the “include” folder that PlatformIO creates in the workspace. I was able to detect some of the headers, but it could not find some of the dependencies for the libraries either. Unfortunately, this did not get me anywhere useful and I still could not include the header file.

Even if this did work, it would only be a temporary solution. I would have to do this each time when creating a new Arduino project with PlatformIO, since the include folder would need these header files once again.

Is there an easy way I can configure platformIO to use the standard C++ libraries by default?

I am thankful for any feedback.

did you find an answer? i am trying to include "string" header file, but i can find a way to include std library

Hey any luck with this? I am facing same issue for one of my projects!

Maybe try a support forum for Visual Studio Code and Platform IO ?

The C++ standard library usually comes with the toolchain. Whether you're using the Arduino IDE or Visual Studio Code + PIO is irrelevant, they both use the same GCC toolchain. The AVR toolchain doesn't include the C++ standard library, because things like std::string and std::vector can be problematic on systems with this little RAM (and also because nobody wants to maintain such a standard library for a niche architecture like AVR where very little people will use it anyway).

If you want decent standard library support, use a more powerful board based on ARM or Espressif chips, for example.
You have third-party implementations for AVR, such as ArduinoSTL or Arduino-Helpers. I maintain the latter one for my own projects and libraries, but AVR is not my main target, and it's just a copy of the GCC C++ standard library made to work on AVR by disabling exceptions and fixing the include paths.

Pieter