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

相关文章

macOS无效Launchpad图标轻松删除的4 种实用方法

《macOS无效Launchpad图标轻松删除的4种实用方法》mac中不在appstore上下载的应用经常在删除后它的图标还残留在launchpad中,并且长按图标也不会出现删除符号,下面解决这个问... 在 MACOS 上,Launchpad(也就是「启动台」)是一个便捷的 App 启动工具。但有时候,应

JSON Web Token在登陆中的使用过程

《JSONWebToken在登陆中的使用过程》:本文主要介绍JSONWebToken在登陆中的使用过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录JWT 介绍微服务架构中的 JWT 使用结合微服务网关的 JWT 验证1. 用户登录,生成 JWT2. 自定义过滤

Linux卸载自带jdk并安装新jdk版本的图文教程

《Linux卸载自带jdk并安装新jdk版本的图文教程》在Linux系统中,有时需要卸载预装的OpenJDK并安装特定版本的JDK,例如JDK1.8,所以本文给大家详细介绍了Linux卸载自带jdk并... 目录Ⅰ、卸载自带jdkⅡ、安装新版jdkⅠ、卸载自带jdk1、输入命令查看旧jdkrpm -qa

Linux samba共享慢的原因及解决方案

《Linuxsamba共享慢的原因及解决方案》:本文主要介绍Linuxsamba共享慢的原因及解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录linux samba共享慢原因及解决问题表现原因解决办法总结Linandroidux samba共享慢原因及解决

Java利用JSONPath操作JSON数据的技术指南

《Java利用JSONPath操作JSON数据的技术指南》JSONPath是一种强大的工具,用于查询和操作JSON数据,类似于SQL的语法,它为处理复杂的JSON数据结构提供了简单且高效... 目录1、简述2、什么是 jsONPath?3、Java 示例3.1 基本查询3.2 过滤查询3.3 递归搜索3.4

新特性抢先看! Ubuntu 25.04 Beta 发布:Linux 6.14 内核

《新特性抢先看!Ubuntu25.04Beta发布:Linux6.14内核》Canonical公司近日发布了Ubuntu25.04Beta版,这一版本被赋予了一个活泼的代号——“Plu... Canonical 昨日(3 月 27 日)放出了 Beta 版 Ubuntu 25.04 系统镜像,代号“Pluc

SpringBoot启动报错的11个高频问题排查与解决终极指南

《SpringBoot启动报错的11个高频问题排查与解决终极指南》这篇文章主要为大家详细介绍了SpringBoot启动报错的11个高频问题的排查与解决,文中的示例代码讲解详细,感兴趣的小伙伴可以了解一... 目录1. 依赖冲突:NoSuchMethodError 的终极解法2. Bean注入失败:No qu

如何自定义Nginx JSON日志格式配置

《如何自定义NginxJSON日志格式配置》Nginx作为最流行的Web服务器之一,其灵活的日志配置能力允许我们根据需求定制日志格式,本文将详细介绍如何配置Nginx以JSON格式记录访问日志,这种... 目录前言为什么选择jsON格式日志?配置步骤详解1. 安装Nginx服务2. 自定义JSON日志格式各

Linux安装MySQL的教程

《Linux安装MySQL的教程》:本文主要介绍Linux安装MySQL的教程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录linux安装mysql1.Mysql官网2.我的存放路径3.解压mysql文件到当前目录4.重命名一下5.创建mysql用户组和用户并修

Linux上设置Ollama服务配置(常用环境变量)

《Linux上设置Ollama服务配置(常用环境变量)》本文主要介绍了Linux上设置Ollama服务配置(常用环境变量),Ollama提供了多种环境变量供配置,如调试模式、模型目录等,下面就来介绍一... 目录在 linux 上设置环境变量配置 OllamPOgxSRJfa手动安装安装特定版本查看日志在