1.下载vscode
wget https://vscode.cdn.azure.cn/stable/0f3794b38477eea13fb47fbe15a42798e6129338/code-1.36.0-1562161214.el7.x86_64.rpm
可以在官网上找自己想要的版本
2.安装
sudo yum install code-1.36.0-1562161214.el7.x86_64.rpm
默认安装包在当前目录下
3. 安装扩展包
code命令打开vscode,ctrl+shift+x打开扩展包的搜索界面,下载如下插件
4.修改配置文件
创建一个文件夹,添加.c文件,按下F5,选择顶部的C++(GDB/LLDB),系统会自动生成.vscode文件夹launch.json,task.json,c_cpp_properties.json文件
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": "gcc - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "gcc build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
task.json
{
"tasks": [
{
"type": "shell",
"label": "gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "/usr/bin"
}
}
],
"version": "2.0.0"
}
具体含义参考官网
https://code.visualstudio.com/docs/editor/variables-reference
如果c_cpp_properties.json文件找不到,可以通过ctrl+shift+p查找
5.添加依赖的头文件
如果编译时候提示头文件找不到,c_cpp_properties.json文件中添加头文件包含目录,如何知道怎么添加呢?
命令:gcc -v -E -x c++ -
这样就可以了