Ubuntu 20.04 下安装配置 VScode 的 C/C++ 开发环境(图文教程)
作者:_NO GAME NO LIFE 时间:2021-12-01 16:48:23
前言:
之前安装了Ubuntu 18.04,结果在安装Codeblocks / VScode还是安装gcc,c/c++的时候出现了一堆错误(缺失依赖树等等问题,换源也无法成功),整了一个下午没有任何进展,网上找不到任何解决方法,于是只能重装了Ubuntu 20.04,之后Codeblocks倒是安装成功了,但是明明在已经安装了C/C++跟GCC编译包的情况,它仍然显示在该路径下找不到,无论路径是默认自动定位在/usr 还是在/usr/bin 之下仍然出现此情况,同样网上找不到任何解决方法,于是只能放弃Codeblocks选用VScode (由于在Windows下一直使用的是Codeblocks,所以才执着于它),幸运的是VScode最终可行
零、Ubuntu镜像文件的选择
Ubuntu官网
VMware Ubuntu 安装教程
一、安装VScode
打开应用商店,搜索VScode,输入密码,等待安装完成即可
引用:Ubuntu16.04下配置VScode的C/C++开发环境
https://www.jb51.net/article/183733.htm
二、配置VScode环境
1.打开VScode,点开Extensions,搜索C++插件安装
2.在任意目录下建立新文件夹(VScode通过文件夹管理工程文件),例我直接在桌面建立
3.在VScode中打开该文件夹
4.在其中建立新文件main.cpp,打开main.cpp,按F5或者点击Run->Starting Debugging,弹出选择环境的框框,选择c++,选择配置则选择第一个g++(大概无所谓吧,反正后面修改配置文件直接全部替换掉)
5.上一步之后将自动生成launch.json,若没出现,则再次点击F5。打开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
}
]
}
]
}
6.修改完launch.json文件后,再次按F5,这次将会出现提示:
“No task to run found. configure tasks...”
然后依次选择
Create tasks.json file from template
Others Example to run an arbitrary external command.
打开task.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"]
}
]
}
三、完成配置,Hello world!
按下F5,输出“Hello world”将在终端中显示,至此完成配置工作!
来源:https://blog.csdn.net/weixin_44012745/article/details/106183331
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
C#实现剪切板功能
详解Java8如何使用Lambda表达式进行比较
java代码实现MD5加密及验证过程详解
使用JSON.toJSONString格式化成json字符串时保留null属性
Gradle的安装和环境变量的配置详解
![](https://img.aspxhome.com/file/2023/2/83552_0s.png)
Android中用Bmob实现短信验证码功能的方法详解
![](https://img.aspxhome.com/file/2023/5/106815_0s.png)
通过Java带你了解网络IO模型
![](https://img.aspxhome.com/file/2023/7/72607_0s.png)
Java反射机制详解
c#使用Unity粒子实现炮塔发射系统
![](https://img.aspxhome.com/file/2023/2/92922_0s.png)
C# 如何合并和拆分PDF文件
![](https://img.aspxhome.com/file/2023/1/119531_0s.png)
Android利用HorizontalScrollView仿ViewPager设计简单相册
![](https://img.aspxhome.com/file/2023/5/96755_0s.png)
Spring Security权限想要细化到按钮实现示例
![](https://img.aspxhome.com/file/2023/5/106155_0s.png)
Mybatis实现SQL存储流程详解
详解SpringBoot定时任务说明
![](https://img.aspxhome.com/file/2023/7/76547_0s.png)
基于Java8 函数式接口理解及测试
详解Jmeter线程组的设置方法
![](https://img.aspxhome.com/file/2023/2/78362_0s.png)
C# memcached缓存使用实例代码
Java ThreadPoolExecutor线程池有关介绍
![](https://img.aspxhome.com/file/2023/6/118896_0s.png)