简体   繁体   English

什么是正确的macOS vscode intellisense C ++包含标准库的路径?

[英]What are the correct macOS vscode intellisense C++ include paths for the standard library?

I am using Visual Studio Code 1.14.2 on macOS Sierra and have installed the Microsoft C/C++ ms-vscode.cpptools extension but am having trouble setting up the include paths to get standard library headers to be correctly inspected by IntelliSense without producing errors and falling back to the 'Tag Parser' mechanism. 我在macOS Sierra上使用Visual Studio Code 1.14.2并安装了Microsoft C / C ++ ms-vscode.cpptools扩展,但是在设置包含路径以使IntelliSense正确检查标准库头时没有产生错误,回到'Tag Parser'机制。

The default c_cpp_properties.json contains the following for this vscode version: 对于此vscode版本,缺省c_cpp_properties.json包含以下内容:

{
  "configurations": [
    {
      "name": "Mac",
      "includePath": [
        "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1",
        "/usr/local/include",
        "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/8.1.0/include",
        "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include",
        "/usr/include",
        "${workspaceRoot}"
      ],
      "defines": [],
      "intelliSenseMode": "clang-x64",
      "browse": {
        "path": [
          "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1",
          "/usr/local/include",
          "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/8.1.0/include",
          "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include",
          "/usr/include",
          "${workspaceRoot}"
        ],
        "limitSymbolsToIncludedHeaders": true,
        "databaseFilename": ""
      }
    },
...
}

For example, with a simple C++ file such as: 例如,使用简单的C ++文件,例如:

#include <exception>

int main() {
    return 0;
}

The #include <exception> is underlined. #include <exception>带有下划线。 Hovering over it states: 悬停在它上面说:

file: 'file:///path/to/vscode.cc' severity: 'Info' message: '#include errors detected. file:'file:///path/to/vscode.cc'严重性:'信息'消息:'#include错误检测到。 Please update your includePath. 请更新您的includePath。 IntelliSense features for this translation unit (/path/to/vscode.cc) will be provided by the Tag Parser.' Tag翻译器将提供此翻译单元的智能感知功能(/path/to/vscode.cc)。 at: '1,1' source: '' at:'1,1'来源:''

and

file: 'file:///path/to/vscode.cc' severity: 'Info' message: 'cannot open source file "endian.h" (dependency of "exception")' at: '1,1' source: '' file:'file:///path/to/vscode.cc'严重性:'Info'消息:'无法打开源文件“endian.h”(依赖于“exception”)'at:'1,1'source: “”

I did a search of my filesystem for endian.h . 我搜索了我的文件系统endian.h Trimming out the possibilities that seem actually relevant for host development (ie dropping iOS/WatchOS/etc.): 调整看起来与主机开发实际相关的可能性(即放弃iOS / WatchOS /等):

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/i386/endian.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/machine/endian.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/i386/endian.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/machine/endian.h
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/i386/endian.h
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/machine/endian.h
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/i386/endian.h
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/machine/endian.h
/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/i386/endian.h
/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/machine/endian.h
/usr/include/i386/endian.h
/usr/include/machine/endian.h

Does anyone know what the correct fix for this issue is? 有谁知道这个问题的正确解决方案是什么?

This turned out to be a configuration bug in the IntelliSense engine. 这竟然是IntelliSense引擎中的配置错误。 Mac headers expected the symbol __LITTLE_ENDIAN__ to be defined and it wasn't. Mac标头需要定义符号__LITTLE_ENDIAN__ ,而不是。 We have corrected this issue in the latest update of the extension, so there is no need to add a path to endian.h anymore. 我们已在最新的扩展更新中更正了此问题,因此无需再添加到endian.h的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM