首先安装 clang和lldb
sudo pacman -S clang
sudo pacman -S lldb
然后安装VScode
yaourt visual-studio-code-bin #我用这种方法安装成功
安装完发现是英文,没关系,我早就知道了你可能更喜欢投入母语的怀抱,下面是VScode汉化教程:
ctrl+alt+p
configure language
locale后面的属性直到冒号,然后重新输入冒号会自动出现代码提示
zh-CN
然后在弹出的搜索框中输入Chinese,然后选择【Chinese (Simplified)Language Pack for Visual Studio Code】,然后点击右侧的【Install】
c_cpp_properties.json的配置文件如下
{
"configurations": [
{
"name": "Linux",
"includePath": [
"/usr/inlcude",
"/usr/local/include",
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"browse":{"path":[
"/usr/inlcude",
"/usr/local/include",
"${workspaceFolder}/**"
]
},
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
找到.vscode文件夹,将文件夹拖入vscode中,创建tasks.json,配置如下:
{
"version": "2.0.0",
"tasks": [
{
"label": "Build with clang", // 任务名称,与launch.json的preLaunchTask相对应
"type":"shell",
"command": "clang++", // 如果用MinGW,编译C用gcc,编译c++用g++
"args": [
"${file}",
"-o", // 指定输出文件名,不加该参数则默认输出a.exe
"${fileDirname}/${fileBasenameNoExtension}.out",
"-g", // 生成和调试有关的信息
"-Wall", // 开启额外警告
"-fcolor-diagnostics",
"-std=c++1z" // c++1z即c++17,C语言最新标准为c11,或根据自己的需要进行修改
], // 编译命令参数
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
"relative",
"/"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$", // 正则表达式,用于描述在“问题”栏中显示的信息。
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
需要安装 negative debugger (如果使用lldb的话,不使用lldb则不需要安装)
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb-mi",
"request": "launch",
"name": "C++ LLDB",
"target": "${fileDirname}/${fileBasenameNoExtension}.out",
"preLaunchTask":"Build with clang", //提前执行的准备,和tasks.json中名字一样
"cwd": "${workspaceRoot}"
},
{
"name": "C++ GDB", // 配置名称,将会在调试配置下拉列表中显示
"type": "cppdbg", // 调试器类型:Windows表示器使用cppvsdbg;GDB和LLDB使用cppdbg。该值自动生成
"request": "launch", // 调试方式
"program": "${fileDirname}/${fileBasenameNoExtension}.out",// 将要进行调试的程序的路径
"args": [], // 传递给上面程序的参数,没有参数留空即可
"stopAtEntry": false, // 是否停在程序入口点(停在main函数开始)
"cwd": "${workspaceRoot}", // 调试程序时的工作目录,一般为${workspaceRoot}即代码所在目录
"environment": [],
"externalConsole": false, // 调试时是否显示控制台窗口
"MIMode": "gdb",
"preLaunchTask":"Build with clang", //提前执行的准备,和tasks.json中名字一样
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}]
}
]
}