Visual Studio Code C++ Extension: Cross-Compilation IntelliSense Configurations
The February 2021 update of the Visual Studio Code C++ extension is now available! This latest release provides support for cross-compilation IntelliSense configurations and over 60 bug fixes! To find out more about all the enhancements, check out our release notes on GitHub.
Cross-compilation IntelliSense configurations
With this latest release, you can configure the extension to provide proper IntelliSense when compiling for a different platform than your host OS. That’s right— platform, not just architecture. The C++ extension no longer hardcodes system defines based on your host OS; it’ll use the system defines returned by your compiler.
Let’s say you’re developing on macOS and your project targets Linux. Assuming you have a compiler compatible with your project’s target platform and architecture, the C++ extension will query that compiler using the Compiler path, Compiler arguments, and IntelliSense mode settings in your IntelliSense configuration. If you’re using a custom configuration provider (like CMake Tools) or compile_commands.json, then you don’t need to worry about updating the C++ extension’s IntelliSense configuration; everything should just work.
Your project’s IntelliSense configurations are stored in the c_cpp_properties.json file under the .vscode folder. Edit these settings by selecting C/C++: Edit Configurations (UI) from the Command Palette.
Under your configuration’s Compiler path setting, enter the path to the compiler compatible with your target platform and architecture.
Then use Compiler arguments to provide the target triplet that you use when cross-compiling your code with your compiler. For example, –target=x86_64-linux if you’re targeting Linux 64-bit. This allows the C++ extension to query the compiler for system defines and include paths specific to your target platform and architecture.
Next, set IntelliSense mode to the platform- and architecture-specific variant of the compiler you’re using (it should closely match the target triplet defined in Compiler arguments). If the information returned from querying the compiler doesn’t match the IntelliSense mode you chose, the C++ extension will automatically correct the IntelliSense mode for you.
Now when you open your project in VS Code, you’ll get IntelliSense for your target platform instead of macOS. No more squiggles from hardcoded system defines!
In addition to supporting cross-compilation IntelliSense configurations, the February 2021 update comes with the following enhancements:
- clang-format has been updated to version 11. #6326
- We now ship a native ARM64 clang-format binary with the extension for ARM64 Windows devices (#6494).
- We added a command to generate EditorConfig contents from your code formatting settings (vcFormat) #6018
- We support a new “console” launch config property for cppvsdbg (replacing the legacy “externalConsole” property). PR #6794
The February 2021 update of the C++ extension knocks out over 60 bug fixes! To name a few:
- Fix clang-format failing due to missing libtinfo5 on Linux ARM/ARM64. #6774
- Fix handling of –sysrootand -isysroot with compileCommands. #1575
- Fix IntelliSense not updating if a non-opened header is changed. #1780
- Fix Switch Header/Source not switching to an existing file in another column if it’s not visible. #2667, #6749
- Allow the extension to run on x64 emulator of M1 Macs. #6713 (Thank you @xymeng16! PR #6601)
- Fix hover and Find All References for template function overloads. #4044, #4249
Check out the release notes for more!
What do you think?
Download the C++ extension for Visual Studio Code today, give it a try, and let us know what you think. If you run into any issues, or have any suggestions, please report them in the Issues section of our GitHub repository. You can also join our Insiders program and get access to early builds of our release by going to File > Preferences > Settings and under Extensions > C/C++, change the “C_Cpp: Update Channel” to “Insiders.” Then under Features > Extensions, enable “Extensions: Auto Update.”