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

How to use vscode-clangd with c++11?

本文关键字:vscode clangd c++11      更新时间:2023-10-16

如何配置vscode clanggd以使用c++11进行lint?

我在车间添加了complie_commands.jsoncomplie_flags.txt

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

compile_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_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
}