非学无以广才,非志无以成学。
本文主要介绍在windows平台上使用WSL环境,基于LLVM工具链结合clangd代码分析,配置C/C++开发环境,在 VScode 上使用 clang 编译 、LLDB 调试和clangd自动补全可以提高编程效率。本文记录了笔者使用VS Code开发的配置环境,供大家参考。
在windows下建议安装WSL环境,可以自行google,安装比较简单的。 笔者使用WSL的ArchLinux系统。如何安装WSL+ArchLinux这里不赘述,可参考链接。
Win10平台安装WSL方法
ArchWSL下载与配置
vscode连接ARCH后,在WSL:ARCH环境安装clangd、CodeLLDB、CMake、CMake Tools、Doxygen Documentation Generator插件。
注意在安装CodeLLDB的时候会报错,vscode会跳出链接,手动下载codelldb-x86_64-linux.vsix。在vscode调出命令窗口安装codelldb,windows平台快捷键ctrl+shift+p,选择Extensions: install from VSIX,选择刚刚下载的codelldb-x86_64-linux.vsix进行安装。
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/build/${fileBasenameNoExtension}",
"args": [],
"cwd": "${workspaceFolder}",
"preLaunchTask": "Build C++",
"internalConsoleOptions": "neverOpen",
"console": "integratedTerminal"
}
]
}
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "Build C++",
"command": "clang",
"args": [
"--std=c++20",
"-g",
"-Wall",
"-o",
"${workspaceFolder}/build/${fileBasenameNoExtension}",
"${file}"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
]
}
sudo pacman -S cmake
sudo pacman -S ninja
project(test)
cmake_minimum_required(VERSION 3.15.0)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF)
add_executable(${CMAKE_PROJECT_NAME} test.cpp)
BasedOnStyle: Microsoft
UseTab: Never
IndentWidth: 4
DerivePointerAlignment: false
PointerAlignment: true
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: true
AlwaysBreakBeforeMultilineStrings: true
AlignOperands: true
AlignAfterOpenBracket: true
AlignConsecutiveBitFields: true
AlignConsecutiveMacros: true
ConstructorInitializerAllOnOneLineOrOnePerLine: true
AllowAllConstructorInitializersOnNextLine: false
BinPackArguments: false
BinPackParameters: false
IncludeBlocks: Regroup
以上就是今天要讲的内容,本文仅仅简单介绍了VS Code结合clangd+CMake的使用,欢迎留言讨论。