[原创]轻松玩转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

相关文章

闲置电脑也能活出第二春?鲁大师AiNAS让你动动手指就能轻松部署

对于大多数人而言,在这个“数据爆炸”的时代或多或少都遇到过存储告急的情况,这使得“存储焦虑”不再是个别现象,而将会是随着软件的不断臃肿而越来越普遍的情况。从不少手机厂商都开始将存储上限提升至1TB可以见得,我们似乎正处在互联网信息飞速增长的阶段,对于存储的需求也将会不断扩大。对于苹果用户而言,这一问题愈发严峻,毕竟512GB和1TB版本的iPhone可不是人人都消费得起的,因此成熟的外置存储方案开

linux-基础知识3

打包和压缩 zip 安装zip软件包 yum -y install zip unzip 压缩打包命令: zip -q -r -d -u 压缩包文件名 目录和文件名列表 -q:不显示命令执行过程-r:递归处理,打包各级子目录和文件-u:把文件增加/替换到压缩包中-d:从压缩包中删除指定的文件 解压:unzip 压缩包名 打包文件 把压缩包从服务器下载到本地 把压缩包上传到服务器(zip

MySQL数据库宕机,启动不起来,教你一招搞定!

作者介绍:老苏,10余年DBA工作运维经验,擅长Oracle、MySQL、PG、Mongodb数据库运维(如安装迁移,性能优化、故障应急处理等)公众号:老苏畅谈运维欢迎关注本人公众号,更多精彩与您分享。 MySQL数据库宕机,数据页损坏问题,启动不起来,该如何排查和解决,本文将为你说明具体的排查过程。 查看MySQL error日志 查看 MySQL error日志,排查哪个表(表空间

JAVA智听未来一站式有声阅读平台听书系统小程序源码

智听未来,一站式有声阅读平台听书系统 🌟 开篇:遇见未来,从“智听”开始 在这个快节奏的时代,你是否渴望在忙碌的间隙,找到一片属于自己的宁静角落?是否梦想着能随时随地,沉浸在知识的海洋,或是故事的奇幻世界里?今天,就让我带你一起探索“智听未来”——这一站式有声阅读平台听书系统,它正悄悄改变着我们的阅读方式,让未来触手可及! 📚 第一站:海量资源,应有尽有 走进“智听

【数据结构】——原来排序算法搞懂这些就行,轻松拿捏

前言:快速排序的实现最重要的是找基准值,下面让我们来了解如何实现找基准值 基准值的注释:在快排的过程中,每一次我们要取一个元素作为枢纽值,以这个数字来将序列划分为两部分。 在此我们采用三数取中法,也就是取左端、中间、右端三个数,然后进行排序,将中间数作为枢纽值。 快速排序实现主框架: //快速排序 void QuickSort(int* arr, int left, int rig

springboot3打包成war包,用tomcat8启动

1、在pom中,将打包类型改为war <packaging>war</packaging> 2、pom中排除SpringBoot内置的Tomcat容器并添加Tomcat依赖,用于编译和测试,         *依赖时一定设置 scope 为 provided (相当于 tomcat 依赖只在本地运行和测试的时候有效,         打包的时候会排除这个依赖)<scope>provided

Linux 网络编程 --- 应用层

一、自定义协议和序列化反序列化 代码: 序列化反序列化实现网络版本计算器 二、HTTP协议 1、谈两个简单的预备知识 https://www.baidu.com/ --- 域名 --- 域名解析 --- IP地址 http的端口号为80端口,https的端口号为443 url为统一资源定位符。CSDNhttps://mp.csdn.net/mp_blog/creation/editor

【Python编程】Linux创建虚拟环境并配置与notebook相连接

1.创建 使用 venv 创建虚拟环境。例如,在当前目录下创建一个名为 myenv 的虚拟环境: python3 -m venv myenv 2.激活 激活虚拟环境使其成为当前终端会话的活动环境。运行: source myenv/bin/activate 3.与notebook连接 在虚拟环境中,使用 pip 安装 Jupyter 和 ipykernel: pip instal

内核启动时减少log的方式

内核引导选项 内核引导选项大体上可以分为两类:一类与设备无关、另一类与设备有关。与设备有关的引导选项多如牛毛,需要你自己阅读内核中的相应驱动程序源码以获取其能够接受的引导选项。比如,如果你想知道可以向 AHA1542 SCSI 驱动程序传递哪些引导选项,那么就查看 drivers/scsi/aha1542.c 文件,一般在前面 100 行注释里就可以找到所接受的引导选项说明。大多数选项是通过"_