ubuntu下vscode的c语言环境搭建

一、安装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”将在终端中显示,至此完成配置工作!

  • 7
    点赞
  • 45
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值