如何配置 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_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
}
由于您在 vscode 中选择 clangd 作为 LSP,因此只需在配置文件中添加一行即可。
cmd/ctrl + shift + p
:首选项:打开用户设置(JSON)settings.json
文件中添加一行: "clangd.fallbackFlags": ["-std=c++11"],
cmd/ctrl + shift + p
: clangd: 重新启动语言服务器繁荣,现在可以了!至于你的“bug”,没有时间重现。
强烈推荐官方手册:编译命令和 clangd 标志