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

时间:2017-08-05 10:34:12

标签: c++ c visual-studio-code vscode-settings

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.

The default c_cpp_properties.json contains the following for this vscode version:

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

#include <exception>

int main() {
    return 0;
}

The #include <exception> is underlined. Hovering over it states:

file: 'file:///path/to/vscode.cc' severity: 'Info' message: '#include errors detected. Please update your includePath. IntelliSense features for this translation unit (/path/to/vscode.cc) will be provided by the Tag Parser.' at: '1,1' source: ''

and

file: 'file:///path/to/vscode.cc' severity: 'Info' message: 'cannot open source file "endian.h" (dependency of "exception")' at: '1,1' source: ''

I did a search of my filesystem for endian.h. Trimming out the possibilities that seem actually relevant for host development (i.e. dropping iOS/WatchOS/etc.):

/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?

1 个答案:

答案 0 :(得分:3)

这是IntelliSense引擎中的配置错误。 Mac标头需要定义符号__LITTLE_ENDIAN__并且它不是。我们已在最新的扩展更新中更正了此问题,因此无需再添加到endian.h的路径。