1) 配置 vscode 编译运行环境
一个工程环境像这样,由一个个单独的c文件组成,彼此不相干
|---- .vscode
|--launch.json
|--tasks.json
|---- foo
|--- bar.cc
|--- bar2.cc
|--- foo_dir2
编译-> 配置tasks.json文件,很简单,为了编译cc文件
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: g++_foo build active file",
"command": "/usr/bin/g++",
"args": [
"-std=c++11",
"-O0",
"-Wall",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"isDefault": true,
"kind": "build"
}
}
]
}
配置launch.json ,顾名思义,配置运行环境
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": ["127.0.0.1" , "8888" ],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++_foo build active file" //关联tasks.json's label
}
]
}
配置settings.json, 在面板中搜索settings.json ,发现在该文件在~/.config/Code/User目录下,
配置clangd
"C_Cpp.intelliSenseEngine": "Disabled",
"clangd.path": "/path/to/your/clangd",
"clangd.arguments": ["-log=verbose",
"-pretty",
"--background-index",
//"--query-driver=/bin/arm-buildroot-linux-gnueabihf-g++", //for cross compile usage
"--compile-commands-dir=/path/to/your/compile_commands_dir/"]
2) 安装clang
- 安装llvm :
sudo apt install llvm
- 安装clang
sudo apt-get install clang
查看安装版本
clang -v
https://zhuanlan.zhihu.com/p/364518020