简体   繁体   中英

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.

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 (ie 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?

This turned out to be a configuration bug in the IntelliSense engine. Mac headers expected the symbol __LITTLE_ENDIAN__ to be defined and it wasn't. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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