microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.53k stars 1.56k forks source link

Latest C/C++ Extension Versions Report <iostream> as Missing with MINGW64 on Windows 11 #12916

Open harnyang opened 1 week ago

harnyang commented 1 week ago

Environment

1.95.1 (user setup) 65edc4939843c90c34d61f4ce11704f09d3e5cb6 2024-10-31T05:14:54.222Z Electron: 32.2.1 ElectronBuildId: 10427718 Chromium: 128.0.6613.186 Node.js: 20.18.0 V8: 12.8.374.38-electron.0 OS: Windows_NT x64 10.0.22631

I’m using the latest version of the C/C++ extension in Visual Studio Code on Windows 11 with the MINGW64 compiler. Here is my compiler information:

C:\Users\Haan>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=D:/software/courseware/minGW/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/14.2.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-14.2.0/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/c/buildroot/x86_64-1420-posix-seh-ucrt-rt_v12-rev0/mingw64 --enable-host-shared --disable-multilib --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --enable-libstdcxx-filesystem-ts=yes --disable-libssp --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=nocona --with-tune=core2 --with-libiconv --with-system-zlib --with-gmp=/c/buildroot/prerequisites/x86_64-w64-mingw32-static --with-mpfr=/c/buildroot/prerequisites/x86_64-w64-mingw32-static --with-mpc=/c/buildroot/prerequisites/x86_64-w64-mingw32-static --with-isl=/c/buildroot/prerequisites/x86_64-w64-mingw32-static --with-pkgversion='x86_64-posix-seh-rev0, Built by MinGW-Builds project' --with-bugurl=https://github.com/niXman/mingw-builds LD_FOR_TARGET=/c/buildroot/x86_64-1420-posix-seh-ucrt-rt_v12-rev0/mingw64/bin/ld.exe --with-boot-ldflags='-pipe -fno-ident -L/c/buildroot/x86_64-1420-posix-seh-ucrt-rt_v12-rev0/mingw64/opt/lib -L/c/buildroot/prerequisites/x86_64-zlib-static/lib -L/c/buildroot/prerequisites/x86_64-w64-mingw32-static/lib  -Wl,--disable-dynamicbase -static-libstdc++ -static-libgcc'
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.2.0 (x86_64-posix-seh-rev0, Built by MinGW-Builds project)

My settings.json in the workspace is configured as follows:

{
    "C_Cpp.errorSquiggles": "enabled",
    "cmake.configureOnOpen": false,
    "cmake.sourceDirectory": "D:/library/dev/code_file/git_learn/test_code",
    "C_Cpp.default.compilerPath": "D:\\software\\courseware\\minGW\\mingw64\\bin\\g++.exe"
}

Additionally, my c_cpp_properties.json file is set up like this:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${default}",
                "${workspaceFolder}/**",
                "D:/software/courseware/minGW/mingw64/lib/**",
                "D:/software/courseware/minGW/mingw64/lib/gcc/x86_64-w64-mingw32/14.2.0/include/C++/**",
                "D:\\software\\courseware\\minGW\\mingw64\\x86_64-w64-mingw32\\include\\**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "intelliSenseMode": "windows-gcc-x64",
            "compilerPath": "D:\\software\\courseware\\minGW\\mingw64\\bin\\g++.exe",
            "cppStandard": "c++11",
            "cStandard": "c99"
        }
    ],
    "version": 4
}

With this setup, my code compiles and runs correctly. However, I’m getting an error indicating that <iostream> cannot be found and that stdlib.h (a dependency of <iostream>) is missing. The error message suggests running "Select IntelliSense Configuration..." to locate system headers. When I trace the error by following the <iostream> include chain, I end up in std_abs.h, where the error is flagged with messages like "expected identifier" and "expected ';'". This issue does not occur with older versions of the C/C++ extension (from two months ago) or when using the clangd extension as the language server. This behavior suggests that there might be a bug in the recent C/C++ extension versions.

Here’s my simple test program, which compiles and runs without issues, despite the header file errors:

#include <iostream>
int main() {
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

Could this be a bug in the latest updates to the C/C++ extension?

Bug Summary and Steps to Reproduce

Bug Summary:

Steps to reproduce:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior:

Configuration and Logs

//c_cpp_properties.json { "configurations": [ { "name": "Win32", "includePath": [ "${default}", "${workspaceFolder}/", "D:/software/courseware/minGW/mingw64/lib/", "D:/software/courseware/minGW/mingw64/lib/gcc/x86_64-w64-mingw32/14.2.0/include/C++/", "D:\software\courseware\minGW\mingw64\x86_64-w64-mingw32\include\" ], "defines": [ "_DEBUG", "UNICODE", "_UNICODE" ], "intelliSenseMode": "windows-gcc-x64", "compilerPath": "D:\software\courseware\minGW\mingw64\bin\g++.exe", "cppStandard": "c++11", "cStandard": "c99" } ], "version": 4 }

Other Extensions

No response

Additional context

No response

Colengms commented 1 week ago

Hi @harnyang . I'm not able to reproduce an issue with your example, when using a default installation of MSYS2 (Using g++.exe from either mingw32, mingw64 or ucrt64 packages).

Could you try setting "C_Cpp.loggingLevel": "Debug" and providing the log output from the C/C++ output channel, from startup until the repro?

The C/C++ extension will 'query' a compiler (if clang or gcc) to solicit its system include paths. It sounds like something may be going wrong with that process. The log of those attempts to query the compiler may provide some clues.

Also, once the issue repro's, could you run the C/C++: Log Diagnostics command, and provide the results? That should indicate exactly what configuration was used for the open file.

                "D:/software/courseware/minGW/mingw64/lib/**",
                "D:/software/courseware/minGW/mingw64/lib/gcc/x86_64-w64-mingw32/14.2.0/include/C++/**",
                "D:\\software\\courseware\\minGW\\mingw64\\x86_64-w64-mingw32\\include\\**"

Since the C/C++ Extension will query system include paths from the configured compiler, you'll want to omit any system include paths from your user includes, as this can result in issues due to include path order.

sean-mcmanus commented 1 week ago

@harnyang In addition, you could be hitting https://github.com/microsoft/vscode-cpptools/issues/12842, i.e. it could be fixed if you try 1.23.0 (pre-release).