1

I have a template class in my header file, I also need a .hpp file for the function implementation.

The issue is with VS Code or MinGW.

In VS Code:

  • I installed the C/C++ extension by Microsoft
  • Here is my c_cpp_properties.json file:

    {
    "configurations": [
        {
            "name": "Win32",
            "intelliSenseMode": "clang-x64",
            "includePath": [
                "${workspaceRoot}",
                "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++",
                "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++/mingw32",
                "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++/backward",
                "C:/MinGW/lib/gcc/mingw32/6.3.0/include",
                "C:/MinGW/include",
                "C:/MinGW/lib/gcc/mingw32/6.3.0/include-fixed"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "__GNUC__=6",
                "__cdecl=__attribute__((__cdecl__))"
            ],
            "browse": {
                "path": [
                    "C:/MinGW/lib/gcc/mingw32/6.3.0/include",
                    "C:/MinGW/lib/gcc/mingw32/6.3.0/include-fixed",
                    "C:/MinGW/include/*"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        }
    ],
    "version": 3
    

    }

  • Here is my settings.json (if needed):

        {
        "files.associations": {
        "iostream": "cpp",
        "ostream": "cpp",
        "*.tcc": "cpp",
        "cctype": "cpp",
        "clocale": "cpp",
        "cstdint": "cpp",
        "cstdio": "cpp",
        "cstdlib": "cpp",
        "cwchar": "cpp",
        "cwctype": "cpp",
        "exception": "cpp",
        "initializer_list": "cpp",
        "iosfwd": "cpp",
        "istream": "cpp",
        "limits": "cpp",
        "new": "cpp",
        "stdexcept": "cpp",
        "streambuf": "cpp",
        "system_error": "cpp",
        "type_traits": "cpp",
        "typeinfo": "cpp",
        "fstream": "cpp"
        },
        "C_Cpp.intelliSenseEngineFallback": "Enabled"
      }
    

I have included the file directory in the environmental variables setting in Windows.

The main issue is in VS Code when I open up the problems window intellisense does not work for .hpp files. This happend to me and one other that I know of. Anyone know of a fix?

I believe this is everything that is needed. (I have included everything where VS Code talks to the compiler)

Spencer Apel
  • 31
  • 2
  • 11
  • Which C++ extension you downloaded? You should install "C/C++ for Visual Studio Code" – 273K Mar 10 '18 at 14:16
  • I installed the C/C++ extension by Microsoft – Spencer Apel Mar 10 '18 at 14:17
  • All looks ok. Have you restarted VS Code? C/C++ extension must download additional binaries after restart and requires restart again. – 273K Mar 10 '18 at 14:21
  • Yes, I have tried disabling the extension, uninstalling and restarting. But for some reason only the hpp files will not work – Spencer Apel Mar 10 '18 at 14:30
  • I do not know, what is incorrect. I have yet one `"*.cpp": "cpp",` in the "files.associations", but it would not help. – 273K Mar 10 '18 at 14:52
  • I've also been trying to get MinGW to work with VScode for the past couple of days. Its like pulling teeth. – Snipe3000 Apr 30 '22 at 07:38

2 Answers2

2

remove the {"name": "Win32"{..}} part and add below part to "configurations":

{
            "name": "MinGW",
            "intelliSenseMode": "clang-x64",
            "compilerPath": "C:/MinGW/bin/gcc.exe",
            "includePath": [
                "${workspaceRoot}",
            ],
            "defines": [
                "_DEBUG"
            ],
            "browse": {
                "path": [
                    "C:/MinGW/lib/gcc/mingw32/6.3.0/include",
                    "C:/MinGW/lib/gcc/mingw32/6.3.0/include-fixed",
                    "C:/MinGW/include/*"
                    "${workspaceRoot}",
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        }

It worked for me on windows with MinGW.

Reference: https://github.com/Microsoft/vscode-cpptools/blob/master/Documentation/LanguageServer/MinGW.md

GorvGoyl
  • 42,508
  • 29
  • 229
  • 225
0

Try to replace the line

"C_Cpp.intelliSenseEngineFallback": "Enabled"

with the line bellow

"C_Cpp.intelliSenseEngine": "Default"

And restart VS Code.

273K
  • 29,503
  • 10
  • 41
  • 64
  • This did not seem to work. I'm starting to think that .hpp files do not have intellisense implemented yet. (Either in VS Code or it is not implemented for MinGW GCC yet..) – Spencer Apel Mar 10 '18 at 15:09
  • In the problems tab? Not in the terminal. If I compile then I will get errors (if some occur) but I "forgot" a semi colon after my statement and I did not get an error until I compiled. For some reason VS Code cannot detect problems in my workspace :'( – Spencer Apel Mar 10 '18 at 15:37
  • Try to add "*.hpp": "cpp" into "files.associations". – 273K Mar 10 '18 at 15:43
  • *For some reason VS Code cannot detect problems in my workspace* This is another thing! IntelliSense is not for detecting errors on fly. – 273K Mar 10 '18 at 15:45
  • Then what is causing it not to detect errors on the fly? – Spencer Apel Mar 10 '18 at 15:54
  • Have you read it? https://github.com/Microsoft/vscode-cpptools/blob/master/Documentation/LanguageServer/MinGW.md – 273K Mar 10 '18 at 16:04