microsoft / vscode-cpptools

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

reported errors in integrating with mingw64 #12836

Open Jessen-Li opened 1 day ago

Jessen-Li commented 1 day ago

Environment

Bug Summary and Steps to Reproduce

Bug Summary: Errors reported as follows:

[10/13/2024, 3:59:28 PM] Unable to resolve configuration with compilerPath "C:/msys64/mingw64/bin/g++.exe". Using "C:\msys64\mingw64\bin\gcc.exe" instead.

Also, problems regarding the cpp file:

cannot open source file "stdlib.h" (dependency of "algorithm"). Please run the 'Select IntelliSense Configuration...' command to locate your system headers.
map is not a template
namespace "std" has no member "vector"
type name is not allowed
identifier "vec" is undefined
namespace "std" has no member "cout"
identifier "cout" is undefined
argument list for variable template "endl" is missing
identifier "vector" is undefined
type name is not allowed

Steps to Reproduce:

  1. install mingw64 on my Win10 Laptop, whose g++ version is C:\Users\li_family>g++ --version g++ (Rev3, Built by MSYS2 project) 14.1.0

  2. In VS Code open a local folder containing my cpp file, say stl.cpp. Setup the VS Code as follows:

settings.json

{
    "C_Cpp.errorSquiggles": "enabled",
    "C_Cpp.default.compilerPath": "C:/msys64/mingw64/bin/g++.exe"
}
c_cpp_properties.json

{
    "configurations": [
        {
            "name": "W32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:/msys64/mingw64/include",
                "C:/msys64/mingw64/include/c++/14.1.0",
                "C:/msys64/mingw64/include/c++/14.1.0/x86_64-w64-mingw32"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:/msys64/mingw64/bin/g++.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-gcc-x64"
        }
    ],
    "version": 4
}

Configuration and Logs

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "W32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:/msys64/mingw64/include",
                "C:/msys64/mingw64/include/c++/14.1.0",
                "C:/msys64/mingw64/include/c++/14.1.0/x86_64-w64-mingw32"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:/msys64/mingw64/bin/g++.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-gcc-x64"
        }
    ],
    "version": 4
}
-------- Diagnostics - 10/14/2024, 10:55:08 AM
Version: 1.21.6
Current Configuration:
{
    "name": "mingw64",
    "includePath": [
        "c:/technical learning/C_C++/**",
        "C:/msys64/mingw64/include",
        "C:/msys64/mingw64/include/c++/14.1.0",
        "C:/msys64/mingw64/include/c++/14.1.0/x86_64-w64-mingw32"
    ],
    "defines": [
        "_DEBUG",
        "UNICODE",
        "_UNICODE"
    ],
    "compilerPath": "C:/msys64/mingw64/bin/g++.exe",
    "cStandard": "c17",
    "cppStandard": "c++17",
    "intelliSenseMode": "gcc-x64",
    "compilerPathIsExplicit": true,
    "cStandardIsExplicit": true,
    "cppStandardIsExplicit": true,
    "intelliSenseModeIsExplicit": true,
    "compilerPathInCppPropertiesJson": "C:/msys64/mingw64/bin/g++.exe",
    "mergeConfigurations": false,
    "browse": {
        "path": [
            "c:/technical learning/C_C++/**",
            "C:/msys64/mingw64/include",
            "C:/msys64/mingw64/include/c++/14.1.0",
            "C:/msys64/mingw64/include/c++/14.1.0/x86_64-w64-mingw32",
            "${workspaceFolder}"
        ],
        "limitSymbolsToIncludedHeaders": true
    }
}
cpptools version (native): 1.21.6.0
Translation Unit Mappings:
[ C:\technical learning\C_C++\STL.cpp - source TU]:
Translation Unit Configurations:
[ C:\technical learning\C_C++\STL.cpp ]:
    Process ID: 4416
    Memory Usage: 97 MB
    Includes:
        C:\msys64\mingw64\include
        C:\msys64\mingw64\include\c++\14.1.0
        C:\msys64\mingw64\include\c++\14.1.0\x86_64-w64-mingw32
    Defines:
        _DEBUG
        UNICODE
        _UNICODE
    Standard Version: ms_c++17
    IntelliSense Mode: windows-msvc-x64
Total Memory Usage: 97 MB

------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 4186

------- Potential include path issues --------
Some headers exist in multiple locations. If IntelliSense is behaving incorrectly,
try adding one of the alternate paths to the "includePath" in your configuration in
c_cpp_properties.json to override the automatic path discovery for that header.

Using: C:/msys64/mingw64/include/c++/14.1.0/map
    Alternative: "C:/technical learning/C_C++"
Using: C:/msys64/mingw64/include/c++/14.1.0/vector
    Alternative: "C:/technical learning/C_C++/vector.dSYM/Contents/Resources/DWARF"

Other Extensions

No response

Additional context

No response

browntarik commented 12 hours ago

We currently recommend that you use the ucrt64 toolchain when installing MinGW. Could you take a look at this documentation and let me know if following these steps helps with you issue: https://code.visualstudio.com/docs/cpp/config-mingw