1.ubuntu->vs code

.  通过官方PPA安装Ubuntu make

sudo add-apt-repository ppa:ubuntu-desktop/ubuntu-make
sudo apt-get update
sudo apt-get install ubuntu-make
. 使用命令安装visual studio code umake ide visual-studio-code 3.使用文件安装:网站下载deb:https://code.visualstudio.com
sudo dpkg -i code_1.38.1-1568209190_amd64.deb

2.vs code配置

tasks可以被用来做编译,而launch用来执行编译好的文件。

2.1 launch.json——告诉VS Code如何执行启动任务

// launch.json

// https://code.visualstudio.com/Docs/editor/debugging#_launch-configurations// Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team
// ${file}: the current opened file
// ${fileBasename}: the current opened file's basename
// ${fileDirname}: the current opened file's dirname
// ${fileExtname}: the current opened file's extension
// ${cwd}: the current working directory of the spawned process
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch", //这个应该是F1中出现的名字
"preLaunchTask": "Build", //在launch之前运行的任务名,这个名字一定要跟tasks.json中的任务名字大小写一致
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe", //需要运行的是当前打开文件的目录中,名字和当前文件相同,但扩展名为exe的程序
"args": [],
"stopAtEntry": false, // 选为true则会在打开控制台后停滞,暂时不执行程序
"cwd": "${workspaceFolder}", // 当前工作路径:当前文件所在的工作空间
"environment": [],
"externalConsole": true, // 是否使用外部控制台,选false的话,我的vscode会出现错误
"MIMode": "gdb",
"miDebuggerPath": "c:/MinGW/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}]
}

2.2 task.json——告诉launch或者编译器需要执行什么操作

// 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", // 任务的名字叫Build,注意是大小写区分的,等会在launch中调用这个名字
"type": "shell", // 任务执行的是shell命令,也可以是
"command": "g++", // 命令是g++
"args": [
"'-Wall'",
"'-std=c++17'", //使用c++17标准编译
"'${file}'", //当前文件名
"-o", //对象名,不进行编译优化
"'${fileBasenameNoExtension}.exe'", //当前文件名(去掉扩展名)
],
// 所以以上部分,就是在shell中执行(假设文件名为filename.cpp)
// g++ filename.cpp -o filename.exe
"group": {
"kind": "build",
"isDefault": true
// 任务分组,因为是tasks而不是task,意味着可以连着执行很多任务
// 在build组的任务们,可以通过在Command Palette(F1) 输入run build task来运行
// 当然,如果任务分组是test,你就可以用run test task来运行
},
"problemMatcher": [
"$gcc" // 使用gcc捕获错误
],
}
]
}

3.gcc/g++

GCC:GNU Compiler Collection(GUN 编译器集合),它可以编译C、C++、JAV、Fortran、Pascal、Object-C、Ada等语言。

gcc是GCC中的GUN C Compiler(C 编译器)

g++是GCC中的GUN C++ Compiler(C++编译器)

3.1 写一个Main.cpp

3.2 输入> g++ -g -c Main.cpp,文件空间下会出现 Main.o。-c只编译生成目标文件并没有形成可执行文件。(-g:添加gdb调试选项。)

3.3输入 g++ -o Main.out Main.o ,文件空间下将会出现 Main.out(可执行文件)。 -o 编译加链接直接生成了可执行文件 .out

所以上面的命令也可以简化为: g++ -o Main.out Main.cpp

4.make/makefile/cmake/CMakeLists.txt

  • make工具通过调用makefile文件中的命令便可以对大型程序进行编译,而makefile文件中就包含了调用gcc去编译多个源文件的命令。
  • 通过cmake我们就可以快速创建出不同平台的makefile文件。如果程序是跨平台,换个平台makefile又要重新修改,这会很麻烦,所以就出现了cmake这个工具。

为了编译一个大型程序,你首先编写CMakeLists.txt。然后,通过cmake命令就可以生成makefile文件。然后通过make命令就可以使用这个makefile文件,其调用gcc从而生成可执行文件。

https://blog.csdn.net/lwwl12/article/details/78189382

参考:https://www.jianshu.com/p/776a5fb57fbb

ubuntu+VS code+launch.json+task.json的更多相关文章

  1. win10下visual studio code安装及mingw C/C++编译器配置,launch.json和task.json文件的配置

    快一年了,我竟然还有脸回来..... 过去一年,由于毕设.找工作的原因,发生太多变故,所以一直没更(最主要的原因还是毅力不够...),至于发生了什么事,以后想说的时候再更吧..依然是小白,下面说正事. ...

  2. Ubuntu Visual code安装与使用

    1.直接启动软件中心,输入visual studio code,点击install即可,千万千万不要去装逼搞什么linux指令安装,死都不知道怎么死的 2.Visual code是以文件夹为工程目录的 ...

  3. 认识Json解析json生成json

    .markdown-body hr::after,.markdown-body::after { clear: both } .loopLine,.messageLine0 { } .markdown ...

  4. json操作json类型转换

    前提是需要加Jar包: gson-2.2.2.jar package utils; import java.io.BufferedReader;import java.io.FileInputStre ...

  5. 一个用httpPost,get访问外网接口,参数json,返回json的示例

    package com.royal.util; import java.io.BufferedReader;import java.io.DataInputStream;import java.io. ...

  6. 深入理解.NET Core的基元: deps.json, runtimeconfig.json, dll文件

    原文链接: Deep-dive into .NET Core primitives: deps.json, runtimeconfig.json, and dll's 作者: Nate McMaste ...

  7. Android-Gson解析JSON数据(JSON对象/JSON数组)

    上一篇博客,Android-解析JSON数据(JSON对象/JSON数组),介绍了使用 org.json.JSONArray;/org.json.JSONObject; 来解析JSON数据: Goog ...

  8. 深入 .NET Core 基础 - 1:deps.json, runtimeconfig.json 以及 dll

    深入 .NET Core 基础:deps.json, runtimeconfig.json 以及 dll 原文地址:https://natemcmaster.com/blog/2017/12/21/n ...

  9. .Net使用Newtonsoft.Json.dll(JSON.NET)对象序列化成json、反序列化json示例教程

    JSON作为一种轻量级的数据交换格式,简单灵活,被很多系统用来数据交互,作为一名.NET开发人员,JSON.NET无疑是最好的序列化框架,支持XML和JSON序列化,高性能,免费开源,支持LINQ查询 ...

随机推荐

  1. 发布delphi程序(build with runtime package)要带哪些文件?

    Delphi提供两种方式来编译你的程序:使用包或者是单独的exe 使用包,你可以使用如下方法设置: 项目选项(菜单project->options->Packages页), 在Runtim ...

  2. 从0开始的InfiniBand硬件踩坑过程

    由于科学计算实验的需求,需要使用InfiniBand做一个持久性内存全互联的分布式存储系统.其中从网卡到交换机使用Mellanox全家桶,而在Mellanox网卡与交换机的使用过程中还是遇到了不少的问 ...

  3. PAT甲级【2019年3月考题】——A1159 Structure_of_a_BinaryTree【30】

    Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and i ...

  4. 使用 内置函数strtok()函数实现 loadrunner 字符串替换

    Action(){ /* loadrunner 字符串替换 */ char separators[] = "/"; char * token; char * file_path; ...

  5. 恐怖的奴隶主(bob)

    题目描述 小L热衷于undercards. 在undercards中,有四个格子.每个格子要么是空的,要么住着一只BigBob. 每个BigBob有一个不超过k的血量:血量减到0视为死亡.那个格子随即 ...

  6. python面试题之简要描述Python的垃圾回收机制(garbage collection)

    这里能说的很多.你应该提到下面几个主要的点: Python在内存中存储了每个对象的引用计数(reference count).如果计数值变成0,那么相应的对象就会小时,分配给该对象的内存就会释放出来用 ...

  7. spring 事物(二)—— 编程式事物实现与扩展

    简介 使用TransactionTemplate 不需要显式地开始事务,甚至不需要显式地提交事务.这些步骤都由模板完成.但出现异常时,应通过TransactionStatus 的setRollback ...

  8. mysql创建用户账号出错

    在数据库中输入“create user 'tom'@'%' identified by '123456';”时,出现“ERROR 1819 (HY000): Your password does no ...

  9. PHP- 搜索插入位置

    给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引.如果目标值不存在于数组中,返回它将会被按顺序插入的位置. 你可以假设数组中无重复元素. 示例 1: 输入: [1,3,5,6], 5输出 ...

  10. 错误描述:fatal error C1010: 在查找预编译头时遇到意外的文件结尾。是否忘记了向源中添加“#include "stdafx.h"”?(转)

    错误分析: 此错误发生的原因是编译器在寻找预编译指示头文件(默认#include "stdafx.h")时,文件未预期结束.没有找到预编译指示信息的头文件"stdafx. ...