【问题标题】:VS Code/MinGW intellisence not working for C++VSCode/MinGW 智能感知不适用于 C++
【发布时间】:2018-03-10 14:09:12
【问题描述】:

我的头文件中有一个模板类,我还需要一个 .hpp 文件来实现函数。

问题在于 VS Code 或 MinGW。

在 VS 代码中:

  • 我安装了微软的 C/C++ 扩展
  • 这是我的 c_cpp_properties.json 文件:

    {
    "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
    

    }

  • 这是我的 settings.json(如果需要):

        {
        "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"
      }
    

我已将文件目录包含在 Windows 的环境变量设置中。

当我打开问题窗口 intellisense 不适用于 .hpp 文件时,主要问题出在 VS Code 中。这发生在我和我所知道的另一个人身上。有谁知道解决办法吗?

我相信这就是我们所需要的一切。 (我已经包含了 VS Code 与编译器对话的所有内容)

【问题讨论】:

  • 您下载了哪个 C++ 扩展?您应该安装“C/C++ for Visual Studio Code”
  • 我安装了微软的 C/C++ 扩展
  • 一切正常。您是否重新启动了 VS Code? C/C++ 扩展必须在重启后下载额外的二进制文件并且需要再次重启。
  • 是的,我已经尝试禁用扩展、卸载并重新启动。但由于某种原因,只有 hpp 文件不起作用
  • 不知道,有什么不对。我在“files.associations”中还有一个"*.cpp": "cpp",,但这无济于事。

标签: c++ visual-studio-code mingw intellisense template-classes


【解决方案1】:

尝试换行

"C_Cpp.intelliSenseEngineFallback": "Enabled"

下面一行

"C_Cpp.intelliSenseEngine": "Default"

然后重启 VS Code。

【讨论】:

  • 这似乎不起作用。我开始认为 .hpp 文件还没有实现智能感知。 (在 VS Code 中或尚未为 MinGW GCC 实现..)
  • 在问题标签中?不在航站楼。如果我编译,那么我会得到错误(如果发生一些错误),但我在我的语句之后“忘记”了一个分号,并且在我编译之前我没有得到错误。出于某种原因,VS Code 无法检测到我的工作区中的问题 :'(
  • 尝试将“*.hpp”:“cpp”添加到“files.associations”中。
  • 由于某种原因 VS Code 无法检测到我的工作区中的问题 这是另一回事! IntelliSense 不适用于实时检测错误。
  • 那是什么原因导致它不能即时检测到错误?
【解决方案2】:

删除{"name": "Win32"{..}} 部分并将以下部分添加到"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": ""
            }
        }

它在带有 MinGW 的 Windows 上对我有用。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-31
    • 1970-01-01
    • 2019-12-28
    • 1970-01-01
    • 2023-02-02
    • 1970-01-01
    • 1970-01-01
    • 2019-11-11
    相关资源
    最近更新 更多