How do you fix Intellisense errors in a CMake project when Visual Studio is connected to WSL:Ubuntu?

Brandon Davies-Sekle 0 Reputation points
2025-12-03T12:38:18.0166667+00:00

I am running a CMake project in Visual Studio Community 2026 and it is connected to WSL: Ubuntu. It is running the Linux Debug configuration preset. WSL is running the gcc 15.1.0 compiler.

My C++ code builds and runs fine but I get hundreds of false-positive Intellisense errors. One example is the following:

Severity Code Description Project File Line Suppression State Details

Error (active) E0020 identifier "_Float32" is undefined CppProgUbuntu - Linux Debug C:\Users\bsekl\AppData\Local\Microsoft\Linux\HeaderCache\1.0\Ubuntu\opt\gcc-15\include\c++\15.1.0\atomic 1692

It is apparent that this is happening because Intellisense is not using the correct system headers and preprocessor definitions for the target environment.

How do I fix this so that Intellisense functions properly and doesn't report false-positive errors?

Developer technologies | Visual Studio | Debugging
0 comments No comments
{count} votes

6 answers

Sort by: Most helpful
  1. Varsha Dundigalla(INFOSYS LIMITED) 3,885 Reputation points Microsoft External Staff
    2025-12-12T11:05:13.02+00:00

    Thank you for reaching out.

    Visual Studio IntelliSense is still using the wrong compiler settings. Even though you added all the include paths and flags, IntelliSense decides which compiler to mimic based on the PATH environment in your CMake preset. If /opt/gcc-15/bin is not first in PATH, IntelliSense falls back to /usr/bin/g++ and ignores the GCC 15 macros (like _Float32), so the squiggles remain.

    1. Add PATH override in your preset In your linux-debug preset, add: "environment": { "PATH": "/opt/gcc-15/bin:${penv:PATH}" } Show more lines This makes sure Visual Studio queries GCC 15 for IntelliSense instead of the default compiler.
    2. Keep these settings you already did:
      • intelliSenseMode: "linux-gcc-x64"
      • CMAKE_EXPORT_COMPILE_COMMANDS: ON
      • copyAdditionalIncludeDirectoriesList and additionalCompilerArgs with -isystem paths.
    3. Clean and rebuild caches:
      • Close the folder in Visual Studio.
      • Delete %LOCALAPPDATA%\Microsoft\Linux\HeaderCache\1.0\Ubuntu.
      • Reopen the project → Delete Cache and ReconfigureBuild All.
    4. Verify detection: After reconfigure, check the CMake output in Visual Studio. It should show:
         C++ compiler: /opt/gcc-15/bin/g++
      
      If it still shows /usr/bin/g++, the PATH override didn’t apply.

    The missing piece is making /opt/gcc-15/bin the first entry in PATH for your preset. Without that, IntelliSense keeps using the wrong compiler macros, causing false errors.

    Please let us know if you require any further assistance, we’re happy to help.

    If you found this information useful, kindly mark this as "Accept Answer".


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.