如何在 c++11 中使用 vscode-clangd?

问题描述 投票:0回答:2

如何配置 vscode-clangd 使用 c++11 进行 lint?

我在工作坊中添加了

complie_commands.json
complie_flags.txt

workshop
|-complie_commands.json
|-complie_flags.txt
|-list.cpp

complie_commands.json

[
   { "directory": "pathto/workshop/",
     "command": "/opt/rh/llvm-toolset-7/root/usr/bin/clang++ -o file *cpp -std=c++11"}
]

compile_flags.txt

-std=c++11

无法识别

auto
,错误:

'auto' type specifier is a C++11 extension
c++ visual-studio-code clang++
2个回答
2
投票

c_cpp_properties.json
中的 cppStandard 设置为
c++11
。例如:

{
  "env": {
    "myDefaultIncludePath": ["${workspaceFolder}", "${workspaceFolder}/include"],
    "myCompilerPath": "/usr/local/bin/gcc-7"
  },
  "configurations": [
    {
      "name": "Linux",
      "intelliSenseMode": "clang-x64",
      "includePath": ["${myDefaultIncludePath}", "/another/path"],
      "macFrameworkPath": ["/System/Library/Frameworks"],
      "defines": ["FOO", "BAR=100"],
      "forcedInclude": ["${workspaceFolder}/include/config.h"],
      "compilerPath": "/usr/bin/clang",
      "cStandard": "c11",
      "cppStandard": "c++11",
      "compileCommands": "/path/to/compile_commands.json",
      "browse": {
        "path": ["${workspaceFolder}"],
        "limitSymbolsToIncludedHeaders": true,
        "databaseFilename": ""
      }
    }
  ],
  "version": 4
}

0
投票

由于您在 vscode 中选择 clangd 作为 LSP,因此只需在配置文件中添加一行即可。

  1. cmd/ctrl + shift + p
    :首选项:打开用户设置(JSON)
  2. 在您的
    settings.json
    文件中添加一行:
    "clangd.fallbackFlags": ["-std=c++11"],
  3. cmd/ctrl + shift + p
    : clangd: 重新启动语言服务器

繁荣,现在可以了!至于你的“bug”,没有时间重现。

强烈推荐官方手册:编译命令和 clangd 标志

© www.soinside.com 2019 - 2024. All rights reserved.