Movatterモバイル変換


[0]ホーム

URL:


TryMCP servers to extend agent mode in VS Code!

Dismiss this update

IntelliSense for cross-compiling

This article is about configuring the C/C++ extension to provide proper IntelliSense (e.g. code completions) in Visual Studio Code when you compile for a different architecture than your development host machine. For example, when your host machine is x64 but you are compiling for Arm.

The C/C++ extension isn't a compiler -- it provides rich language features such as syntax highlighting and IntelliSense. For the extension to provide correct IntelliSense suggestions and to reflect the right sizes of data types, you need to configure the C++ extension to emulate the target architecture.

These configuration settings are stored in your project'sc_cpp_properties.json file. To edit this file, in VS Code, selectC/C++: Edit Configurations (UI) from the Command Palette (⇧⌘P (Windows, LinuxCtrl+Shift+P)):

Command Palette

Example IntelliSense configuration

The following shows configuring the C/C++ extension for a Linux x64 host machine that targets Linux Arm. It configures the following IntelliSense settings:

  • Compiler path: the extension queries your compiler at this location to retrieve system libraries and compiler defines.
  • IntelliSense mode: emulates the target architecture and compiler so that the extension can provide correct IntelliSense and reflect the right sizes of data types such aspointer,size_t,long, and so on.

At a minimum, settingcompiler path andIntelliSense mode provides enough information for the extension to emulate your project's target architecture, although settingIntelliSense mode may not be needed if the extension is able to choose it correctly based on the defines returned from querying thecompiler path.

Compiler path

Set to the full path of the compiler you are using to build your project.

For example:

Compiler path setting

IntelliSense mode

Set to the architecture-specific variant of the compiler you are using.

For example:

IntelliSense mode setting

Include path

You only need to modify theInclude path if your program includes header files that aren't in your workspace or that are not in the standard library path.

The C/C++ extension populates the include path by querying the compiler specified byCompiler path. If the extension can't find the path for the target system libraries, you can enter the include path manually:

Include path setting

Given the settings above, yourc_cpp_configuration.json file will look something like the following. You can open it by selectingC/C++: Edit Configurations (JSON) from the Command Palette:

{  "configurations": [    {      "name":"myConfigurationName",      "includePath": ["${workspaceFolder}/**"],      "defines": [],      "compilerPath":"/usr/bin/arm-none-eabi-g++",      "cStandard":"c11",      "cppStandard":"c++14",      "IntelliSenseMode":"gcc-arm"    }  ],  "version":4}

Next steps

1/17/2023

[8]ページ先頭

©2009-2025 Movatter.jp