Ubuntu16.04下配置VScode的C/C++开发环境

2020-03-29 14:01:06王振洲

 

这里在launch.json文件中添加了”preLaunchTask“=”build",也就是添加一个launch之间的任务,任务名为build,这个build就是我们在tasks.json中设置的任务名。

3.总结及注意事项

本文对Ubuntu16.04系统下配置基于VScode的C/C++开发环境进行了简单的介绍,主要步骤为:

1.安装VScode,可以通过在官网下载和命令行的方式进行安装。(顺便提一下,在命令行安装的过程中可能会让你输入a)

2.新建C/C++工程,VScode以文件夹为管理工程的方式,因此需要建立一个文件夹来保存工程。

3.配置launch.json文件,它是一个启动配置文件。需要进行修改地方的是指定运行的文件,其次我们还可以在里面添加build任务。

4.配置tasks.json文件,这个文件用来方便用户自定义任务,我们可以通过这个文件来添加g++/gcc或者是make命令,方便我们编译程序。

5.上述四个流程完了之后我们就可以进行基础的C/C++开发与调试了。

4. 附录

这里给出一个较完整的配置文件和任务文件,笔者的系统的Ubuntu16.04 LTS,测试时间是2018/11/14。由于版本不同可能会有所变化,因此该配置仅供参考!

(1)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
  }
  ]
 }
 ]
}

(2)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"]
 }
 ]
}

总结

到此这篇关于Ubuntu16.04下配置VScode的C/C++开发环境的文章就介绍到这了,更多相关Ubuntu16.04下配置VScode的C/C++开发环境内容请搜索易采站长站以前的文章或继续浏览下面的相关文章希望大家以后多多支持易采站长站!