In this post, 3 VSCode c analysis and support topics:
- how to set the c/c++ standard (e.g.: the new c++20 standard) for the IntelliSense extension
- how make IntelliSense find the right includes for the Pico and the c SDK
- how to tell IntelliSense that you use a cross-platform toolchain?
IntelliSense is the extension that enables code auto-complete and popup code insight for c and c++ code. It is the module that shows you the "squiggly lines" when you make an error against language constructs.
You can change settings via the extension editor, or directly in the .vscode/c_cpp_properties.json file. Both options are available from the command palette when you press CTRL+SHIFT+P -> C/C++: Edit Configurations(UI/JSON). I'm going to use the JSON text editor in this blog and show the contents directly.
IntelliSense defaults to the OS platform, and to the compiler you set in the extension's config. I'm making a new configuration for Pico on my cross-compile platform (OS: Windows. Compiler: arm-none-eabi).
{ "configurations": [ { "name": "Pico", "includePath": [ "${workspaceFolder}/**", "C:/Users/jancu/Documents/Pico/pico-sdk/src/**" ], "defines": [ "_DEBUG", "UNICODE", "_UNICODE" ], "windowsSdkVersion": "10.0.19041.0", "compilerPath": "C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.10/bin/arm-none-eabi-gcc.exe", "cStandard": "c11", "cppStandard": "c++20", "intelliSenseMode": "gcc-arm", "configurationProvider": "ms-vscode.makefile-tools" } ], "version": 4 }
c/c++ standard
It's best to set the IntelliSense language the same as the ones in your CMake settings. If you have this in CMakeList.txt:
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 20)
then set the same ones in the IntelliSense config:
"cStandard": "c11",
"cppStandard": "c++20",
include path for Pico board and SDK
To take care that IntelliSense can find Pico related includes, add this:
"includePath": [
"${workspaceFolder}/**",
"C:/Users/jancu/Documents/Pico/pico-sdk/src/**"
set the cross-platform ARM toolchain
VSCode defaults to your platform. If you run a Windows install on an Intel architecture, it will default to that. We want that it does the checking for the ARM family. In the mean time, setting the compiler path will also automatically resolve all toolchain related include paths.
"compilerPath": "C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.10/bin/arm-none-eabi-gcc.exe",
"intelliSenseMode": "gcc-arm",
references:
- VSCode documentation: IntelliSense for cross-compiling