ubuntu 20.04安装visual studio code并配置C++编译环境

1.下载安装visual studio code

我的系统是Ubuntu20.04,首先是下载安装包。进入官网,直接下载压缩包。
https://code.visualstudio.com/Download

在这里插入图片描述

下载完成后双击安装即可。

 2.C++运行环境配置

插件的安装

在这里插入图片描述

汉化:

过于简单,直接按照教程操作:https://jingyan.baidu.com/article/7e44095377c9d12fc1e2ef5b.html

3.新建项目并运行:

我在主目录建了一个新的文件夹,名为VSCode

然后使用VS打开它,参考图片:

在这里插入图片描述

新建main.cpp文件并输入程序:

在这里插入图片描述

参考程序:

#include <iostream>
using namespace std;
int main()
{
    cout << "Hello world" << endl;
    getchar();
    return 0;
}

然后点击左边的运行按钮,点击运行和调试,

选择C++(GDB/LLDB):

 

然后选择gcc:

直接运行一下,会出错,但是文件那边会多出一个tasks.jsonlaunch.json文件,如果没有,手动创建两个文件,这个也是我们需要修改的文件,修改为如下内容:

 

tasks.json:

{
	// 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"]
	}]
}

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": "${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
		}]
	}]
}

每一次运行都返回到cpp代码界面,注意退出上一次的运行.

再一次返回cpp界面,点击运行或者按下F5

 

到这里C++ 代码就在Ubuntu20.04上跑起来了。环境搭建完成,就可以进行激动人心的学习了。

 

参考文章:

https://blog.csdn.net/qq_40495217/article/details/91351470
https://jingyan.baidu.com/article/7e44095377c9d12fc1e2ef5b.html
https://sidney.blog.csdn.net/article/details/111938091?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.control&dist_request_id=e2ed650b-01a6-4d80-bd9c-42ab59ac7f48&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.control

  • 8
    点赞
  • 53
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值