基于Ubuntu的vscode安装与简单使用
1.vscode的安装
1.1 下载vscode
这里提供一种简单的安装方法——图形操作界面安装(在终端的安装方法参考博客1、博客2等)
直接在ubuntu应用商店搜索Visual Studio Code然后点击安装等待即可
1.2 汉化vscode
按键CTRL+P打开命令行输入命令:
>Configure Language
然后依次选择“Configure Display Language”-“Install additional languages…”选择中文安装即可。
安装完后重启即可
汉化之后我们操作起来就更加舒服,有中文汉化包我们为什么要看英文呢?
2.vscode的配置
2.1 安装c/c++插件
按键CTRL+P打开命令行输入命令:
ext install cpptools
然后选择第一个**c/c++**安装下载后重启即可
3.vscode的使用
3.1 打开文件夹
按图示操作
选择要调试文件所在文件夹即可
3.2 配置launch.json文件
按图示操作
再点击gcc-7即可生成
并且修改成下述命令:
{
{{
// 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": "${workspaceFolder}/hello.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
],
"preLaunchTask":"build",
}
3.3 生成tasks.json文件
按图示操作
生成后修改如下
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "gcc hello.c -o a.out",
"args": [
"-g",
"${file}",
"-std=c++11",
"-o",
"${fileBasenameNoExtension}.out"
]
}
]
}
3.4 编译运行调试
按键CTRL+SHIFT+B编译
点击绿色
4.总结
通过本次实验,对vscode的使用,可以在ubuntu下用图形界面来调试程序,比gdb要高效。但是需要配置更改 .json 文件,这是比较麻烦的一点。