VSCode IntelliSense not working with cross-compile

I have set up a cross compilation workflow according to the Toradex C++ examples for VSCode for my device. What basically happens is that my app is built in a docker container on an amd64 wsl and then the build output is put into the mounted volume that is shared with the project folder. Deploying and debugging this code on the device also works well.

However, I do now have the issue that Intellisense and the VSCode C++ extension does not work properly because it cannot find any includes etc., so auto-completions etc all does not work. I tried to solve this with generating also a Cmake compile_commands.json, however this also has 2 problems: 1. the pathes in the compile_commands.json are the once of the corss-compile container and not of the workspace folder, so these links do not work 2. system libraries are obviously only present in the cross-compile docker container and not on the developer machine/wsl.

So overall my question is, what is the proposed way with this setup to also make Intellisense/Auto-Completions etc. properly work in VSCode?

Hi, I’m the Toradex AI Assistant.

I might make mistakes. Our support team will step in if needed. If I answered your question, please tick the “Solution” checkbox. For follow-up questions to me, please use @ToradexAI in your post.

Did you like my answer? :+1: :-1:


Hello! Thank you for your detailed question.

You have correctly identified two of the main challenges when working with cross-compilation for embedded Linux using the VSCode C++ extension and Docker containers:

  1. Path mismatch: The compile_commands.json generated inside the SDK container uses paths that exist inside the container, not in your VSCode workspace.
  2. System headers/libraries: The container contains the sysroots and libraries for your target (e.g., ARM), but your development environment (e.g., WSL or Windows) does not.

Recommended Approach

Here are best practices to enable proper IntelliSense/autocompletion in this workflow:


1. Use Workspace in Linux Filesystem (WSL Case)

For Windows users with WSL, ensure your workspace is located in the WSL Linux filesystem (e.g., /home/<username>/myproject) and not on a Windows mount like /mnt/c/.... This prevents path conversion issues and file access errors:

Workspace Files and Files Inside Containers


2. Generate compile_commands.json in a Location That Matches Host Paths

You’re correct that compile_commands.json paths will refer to container locations. Consider the following options:

  • Option A: Mirror Paths

    • When starting your container, map your workspace at the same path as it is accessible from VSCode/WSL. For example, /home/<username>/myproject. This way, the paths in compile_commands.json align with your editor’s view.
  • Option B: Path Mapping (Advanced)

    • Use VSCode’s C++ configuration (c_cpp_properties.json) to specify compileCommands and, if needed, browse.path or includePath entries that mimic the container’s sysroot as much as possible.

3. Make Target Sysroot Accessible to IntelliSense

IntelliSense works best when it has access to the same include files as the container. Here are some methods:

  • Export System Includes from Container

    • Copy (or bind-mount) the sysroot includes from your container to the workspace or another host-accessible location.
    • Add these directories to your c_cpp_properties.json’s includePath.
  • Extract Includes Using the SDK

    • If using the SDK container image, you might extract /usr/include, /usr/local/include, and any relevant cross-toolchain include paths to your host, then reference these in your workspace configuration.

Example C++ Extension Configuration

Example c_cpp_properties.json:

{
  "configurations": [
    {
      "name": "Linux",
      "includePath": [
        "${workspaceFolder}/**",
        "/path/to/sysroot/usr/include",
        "/path/to/sysroot/usr/local/include"
      ],
      "compileCommands": "${workspaceFolder}/build/compile_commands.json",
      "defines": [],
      "compilerPath": "/usr/bin/arm-linux-gnueabihf-gcc",
      "cStandard": "c11",
      "cppStandard": "c++17",
      "intelliSenseMode": "linux-gcc-arm"
    }
  ],
  "version": 4
}

Adjust /path/to/sysroot/ to the path you made accessible from the container or exported.


4. Summary

  • Place your workspace in WSL/Linux filesystem (not /mnt/c/).
  • Mirror the source tree path between host and container to synchronize paths in compile_commands.json.
  • Provide the system and toolchain include directories (copied from SDK container) to IntelliSense.

For more information, refer to the official documentation.

If you’d like, I can provide more details on exporting sysroot headers or configuring specific VSCode settings.

Best regards,
Toradex AI Assistant.