Ubuntu vscode配置c/c++环境
对Linux小白我来说,这次vscode配置c/c++环境可费了我不少功夫,(强调!!必须确保Linux系统已经具有g++环境,否则会出现.out路径查找不到错误)首先网上的资料真的千奇百怪,见怪不怪,参差不齐,没说前提,只说结果,云里雾里的。。所以今天,要写vscode配置c/c++环境详细文章,适用于刚安装Linux系统的小白,当然也适合大佬已经配好g++环境的
Ubuntu 配置g++ 环境
Linux系统安装vim,已安装可忽略
查看本机是否已经配置g++环境,若显示如图,则按下面步骤安装g++环境,若已安装则忽略该步骤。
确定g++安装成功
写一个简单的hello World测试一下,若成功,则Ubuntu 配置g++ 成功
如图所示则继续下一步骤
vscode配置c/c++环境
打开vscode,vscode商店安装插件如图,并按图中进行操作
随意创建vscode工作区,在演示中在创建了gogogo文件夹承载工作
文件目录如下
在工作区下创建cpp文件,按F5执行文件,后点击调试,自动跳转到lanuch.json文件夹下,并将lanuch.json文件进行覆盖
// An highlighted block
{
// 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}/${fileBasenameNoExtension}.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"preLaunchTask": "build",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
并在终端下运动任务,自动跳转到task.json文件下,同样的操作,对task内文件进行覆盖
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": ["-g", "${file}", "-std=c++11", "-o", "${fileBasenameNoExtension}.out"]
}
]
}
处理之后切记切记,不能跳过g++的配置直接到vscode 的c/c++的配置,否则无论如何修改,都会像我一样,导致配置c++的运行环境中,出现launch:program"路径.out"does not exist 错误。然后就会陷入无休止的循环。如上博客内容如有错误,敬请评论指出!