[原创]轻松玩转vscode launch.json tasks.json linux启动c程序编译c程序

2024-05-04 10:58

本文主要是介绍[原创]轻松玩转vscode launch.json tasks.json linux启动c程序编译c程序,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

编译c++网上的确有现成的插件,但是一点都不好用,比如需要传递个参数就蛋疼了。
技巧1: 自定义快捷键编译
技巧2:自定义编译命令
launch.json

{"version": "0.2.0","configurations": [{"name": "C++ Launch","cwd": "${workspaceFolder}","type": "cppdbg","request": "launch","preLaunchTask": "compile",// "program3": "${workspaceRoot}/a.out","program": "${fileDirname}/${fileBasenameNoExtension}",// "program": "${fileDirname}/${fileBasenameNoExtension}","stopAtEntry": false,// "setupCommands": [//     {//         "description": "Enable pretty-printing for gdb",//         "text": "-enable-pretty-printing",//         "ignoreFailures": true//     }// ],// "customLaunchSetupCommands": [//     {//         "text": "target-run",//         "description": "run target",//         "ignoreFailures": false//     }// ],"launchCompleteCommand": "exec-run","linux": {"MIMode": "gdb","miDebuggerPath": "/usr/bin/gdb"},"osx": {"MIMode": "lldb"},"windows": {"MIMode": "gdb","miDebuggerPath": "C:\\MinGw\\bin\\gdb.exe"}}],"configurations1": [{"name": " Launch C","type": "cppdbg","request": "launch","program": "{fileDirname}/${fileBasenameNoExtension}","args": [],"stopAtEntry": false,"cwd": "${workspaceFolder}","preLaunchTask1": "compile","environment": [],"externalConsole": false,"MIMode": "gcc","setupCommands": [{"description": "Enable pretty-printing for gdb","text": "-enable-pretty-printing","ignoreFailures": true}]}]
}

tasks.json

{// See https://go.microsoft.com/fwlink/?LinkId=733558//ctrl shift p choose task// for the documentation about the tasks.json format"version": "2.0.0","tasks": [{"label": "compile","type": "shell","command": "echo compile exeover&g++ -g  ${file} -o ${fileDirname}/${fileBasenameNoExtension}",// "command": "g++ ${file} -o ${fileDirname}/${fileBasenameNoExtension}&echo compile exeover&${fileDirname}/${fileBasenameNoExtension}","cwd": "${workspaceFolder}","presentation": {"reveal": "always","panel": "new"},"group": {"kind": "build","isDefault": true}},{"label": "compileRun","type": "shell",// "command": "echo compile exeover&g++ -g  ${file} -o ${fileDirname}/${fileBasenameNoExtension}","command": "g++ -g -g -Wall -std=c++11 ${file} -o ${fileDirname}/${fileBasenameNoExtension} -lpthread&&echo [-----compileSucc----]&&${fileDirname}/${fileBasenameNoExtension}&&echo [----executeSucc----]","args": [ //传递给命令的参数{//    "value": "","quoting": "escape" //指定对内容的escape}],"problemMatcher": [],"options": {"cwd": "${fileDirname}","env": { //wsl的环境变量支持有问题,设置不生效"MY_NAME": "aaaaaaa"},"shell": { //shell执行的一些配置"executable": "bash","args": ["-c"]},},"presentation": {"echo": false,//如果 为false,怎么执行命令是不会提示的,但是 程序里面的控制信息是会执行的."reveal": "always",// "reveal": "never",//揭露 总是 显示信息不然搞毛."focus": false,"panel": "shared",//面板就是每次启动的时候是否新开 dedicated专用 ,shared保留之前"clear": true,//每次变异 是否清屏."showReuseMessage": false// 不是,true就提示enter,否则 还是需要按enter 就是提示那个英文而已但是并不会自动关闭},"group": {"kind": "build","isDefault": true}}]
}

cpp_properties这个配置需要微软的插件。

{"configurations": [{"name": "Linux","includePath": ["${workspaceFolder}/**"],"defines": [],"compilerPath": "/usr/bin/gcc","cStandard": "c11","cppStandard": "c++14","intelliSenseMode": "clang-x64"}],"version": 4
}

快捷键启动指定的task实现编译操作

{"key": "ctrl+b","command": "workbench.action.tasks.runTask","args": "compileRun"}

我配置的所有快捷键

// 使用当前快捷键设置覆盖默认设置
[{"key": "alt+d","command": "editor.action.deleteLines","when": "editorFocus"},{"key": "alt+w","command": "editor.action.moveLinesUpAction","when": "editorTextFocus"},{"key": "alt+s","command": "editor.action.moveLinesDownAction","when": "editorTextFocus"},{"key": "ctrl+shift+f","command": "editor.action.format","when": "editorTextFocus"},{"key": "f7","command": "workbench.action.debug.stepOut","when": "inDebugMode"},{"key": "alt+u","command": "cursorHome","when": "editorTextFocus"},{"key": "alt+o","command": "cursorEnd","when": "editorTextFocus"},{"key": "ctrl+j","command": "workbench.action.gotoLine"},{"key": "f6","command": "workbench.action.debug.stepOver","when": "inDebugMode"},{"key": "shift+s","command": "editor.action.insertLineAfter","when": "editorTextFocus"},{"key": "shift+w","command": "editor.action.insertLineBefore","when": "editorTextFocus"},{"key": "alt+n","command": "editor.action.copyLinesDownAction","when": "editorTextFocus"},{"key": "f5","command": "workbench.action.debug.stepInto","when": "inDebugMode"},{"key": "alt+i","command": "cursorUp","when": "textInputFocus&& !parameterHintsVisible &&!suggestWidgetVisible"},{"key": "alt+k","command": "cursorDown","when": "textInputFocus"},{"key": "alt+j","command": "cursorLeft","when": "textInputFocus"},{"key": "alt+l","command": "cursorRight","when": "textInputFocus"},{"key": "alt+k","command": "showNextParameterHint","when": "editorTextFocus && parameterHintsMultipleSignatures && parameterHintsVisible"},{"key": "alt+k","command": "showPrevParameterHint","when": "editorTextFocus && parameterHintsMultipleSignatures && parameterHintsVisible"},{"key": "alt+k","command": "selectNextSuggestion","when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus"},{"key": "alt+i","command": "selectPrevSuggestion","when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus"},{"key": "alt+/","command": "editor.action.triggerSuggest","when": "editorHasCompletionItemProvider && textInputFocus && !editorReadonly"},{"key": "shift+alt+r","command": "renameFile","when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus"},{"key": "alt+shift+r","command": "editor.action.codeAction","args": {"kind": "refactor.extract.function"},"when": "editorTextFocus"},{"key": "f2","command": "-renameFile","when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus"},{"key": "alt+shift+r","command": "editor.action.changeAll","when": "editorTextFocus && !editorReadonly"},{"key": "ctrl+b","command": "workbench.action.tasks.runTask","args": "compileRun"}
]

我的项目源码https://github.com/qssq/linuxcpp/tree/master/.vscode

这篇关于[原创]轻松玩转vscode launch.json tasks.json linux启动c程序编译c程序的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/959041

相关文章

IDEA编译报错“java: 常量字符串过长”的原因及解决方法

《IDEA编译报错“java:常量字符串过长”的原因及解决方法》今天在开发过程中,由于尝试将一个文件的Base64字符串设置为常量,结果导致IDEA编译的时候出现了如下报错java:常量字符串过长,... 目录一、问题描述二、问题原因2.1 理论角度2.2 源码角度三、解决方案解决方案①:StringBui

Linux使用nload监控网络流量的方法

《Linux使用nload监控网络流量的方法》Linux中的nload命令是一个用于实时监控网络流量的工具,它提供了传入和传出流量的可视化表示,帮助用户一目了然地了解网络活动,本文给大家介绍了Linu... 目录简介安装示例用法基础用法指定网络接口限制显示特定流量类型指定刷新率设置流量速率的显示单位监控多个

ElasticSearch+Kibana通过Docker部署到Linux服务器中操作方法

《ElasticSearch+Kibana通过Docker部署到Linux服务器中操作方法》本文介绍了Elasticsearch的基本概念,包括文档和字段、索引和映射,还详细描述了如何通过Docker... 目录1、ElasticSearch概念2、ElasticSearch、Kibana和IK分词器部署

Linux流媒体服务器部署流程

《Linux流媒体服务器部署流程》文章详细介绍了流媒体服务器的部署步骤,包括更新系统、安装依赖组件、编译安装Nginx和RTMP模块、配置Nginx和FFmpeg,以及测试流媒体服务器的搭建... 目录流媒体服务器部署部署安装1.更新系统2.安装依赖组件3.解压4.编译安装(添加RTMP和openssl模块

linux下多个硬盘划分到同一挂载点问题

《linux下多个硬盘划分到同一挂载点问题》在Linux系统中,将多个硬盘划分到同一挂载点需要通过逻辑卷管理(LVM)来实现,首先,需要将物理存储设备(如硬盘分区)创建为物理卷,然后,将这些物理卷组成... 目录linux下多个硬盘划分到同一挂载点需要明确的几个概念硬盘插上默认的是非lvm总结Linux下多

Android里面的Service种类以及启动方式

《Android里面的Service种类以及启动方式》Android中的Service分为前台服务和后台服务,前台服务需要亮身份牌并显示通知,后台服务则有启动方式选择,包括startService和b... 目录一句话总结:一、Service 的两种类型:1. 前台服务(必须亮身份牌)2. 后台服务(偷偷干

在不同系统间迁移Python程序的方法与教程

《在不同系统间迁移Python程序的方法与教程》本文介绍了几种将Windows上编写的Python程序迁移到Linux服务器上的方法,包括使用虚拟环境和依赖冻结、容器化技术(如Docker)、使用An... 目录使用虚拟环境和依赖冻结1. 创建虚拟环境2. 冻结依赖使用容器化技术(如 docker)1. 创

linux进程D状态的解决思路分享

《linux进程D状态的解决思路分享》在Linux系统中,进程在内核模式下等待I/O完成时会进入不间断睡眠状态(D状态),这种状态下,进程无法通过普通方式被杀死,本文通过实验模拟了这种状态,并分析了如... 目录1. 问题描述2. 问题分析3. 实验模拟3.1 使用losetup创建一个卷作为pv的磁盘3.

轻松上手MYSQL之JSON函数实现高效数据查询与操作

《轻松上手MYSQL之JSON函数实现高效数据查询与操作》:本文主要介绍轻松上手MYSQL之JSON函数实现高效数据查询与操作的相关资料,MySQL提供了多个JSON函数,用于处理和查询JSON数... 目录一、jsON_EXTRACT 提取指定数据二、JSON_UNQUOTE 取消双引号三、JSON_KE

MySQL数据库函数之JSON_EXTRACT示例代码

《MySQL数据库函数之JSON_EXTRACT示例代码》:本文主要介绍MySQL数据库函数之JSON_EXTRACT的相关资料,JSON_EXTRACT()函数用于从JSON文档中提取值,支持对... 目录前言基本语法路径表达式示例示例 1: 提取简单值示例 2: 提取嵌套值示例 3: 提取数组中的值注意