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

相关文章

SpringBoot通过main方法启动web项目实践

《SpringBoot通过main方法启动web项目实践》SpringBoot通过SpringApplication.run()启动Web项目,自动推断应用类型,加载初始化器与监听器,配置Spring... 目录1. 启动入口:SpringApplication.run()2. SpringApplicat

解决Nginx启动报错Job for nginx.service failed because the control process exited with error code问题

《解决Nginx启动报错Jobfornginx.servicefailedbecausethecontrolprocessexitedwitherrorcode问题》Nginx启... 目录一、报错如下二、解决原因三、解决方式总结一、报错如下Job for nginx.service failed bec

Linux实现查看某一端口是否开放

《Linux实现查看某一端口是否开放》文章介绍了三种检查端口6379是否开放的方法:通过lsof查看进程占用,用netstat区分TCP/UDP监听状态,以及用telnet测试远程连接可达性... 目录1、使用lsof 命令来查看端口是否开放2、使用netstat 命令来查看端口是否开放3、使用telnet

Linux系统管理与进程任务管理方式

《Linux系统管理与进程任务管理方式》本文系统讲解Linux管理核心技能,涵盖引导流程、服务控制(Systemd与GRUB2)、进程管理(前台/后台运行、工具使用)、计划任务(at/cron)及常用... 目录引言一、linux系统引导过程与服务控制1.1 系统引导的五个关键阶段1.2 GRUB2的进化优

Python脚本轻松实现检测麦克风功能

《Python脚本轻松实现检测麦克风功能》在进行音频处理或开发需要使用麦克风的应用程序时,确保麦克风功能正常是非常重要的,本文将介绍一个简单的Python脚本,能够帮助我们检测本地麦克风的功能,需要的... 目录轻松检测麦克风功能脚本介绍一、python环境准备二、代码解析三、使用方法四、知识扩展轻松检测麦

基于Python编写自动化邮件发送程序(进阶版)

《基于Python编写自动化邮件发送程序(进阶版)》在数字化时代,自动化邮件发送功能已成为企业和个人提升工作效率的重要工具,本文将使用Python编写一个简单的自动化邮件发送程序,希望对大家有所帮助... 目录理解SMTP协议基础配置开发环境构建邮件发送函数核心逻辑实现完整发送流程添加附件支持功能实现htm

Linux查询服务器 IP 地址的命令详解

《Linux查询服务器IP地址的命令详解》在服务器管理和网络运维中,快速准确地获取服务器的IP地址是一项基本但至关重要的技能,下面我们来看看Linux中查询服务器IP的相关命令使用吧... 目录一、hostname 命令:简单高效的 IP 查询工具命令详解实际应用技巧注意事项二、ip 命令:新一代网络配置全

linux安装、更新、卸载anaconda实践

《linux安装、更新、卸载anaconda实践》Anaconda是基于conda的科学计算环境,集成1400+包及依赖,安装需下载脚本、接受协议、设置路径、配置环境变量,更新与卸载通过conda命令... 目录随意找一个目录下载安装脚本检查许可证协议,ENTER就可以安装完毕之后激活anaconda安装更

C#控制台程序同步调用WebApi实现方式

《C#控制台程序同步调用WebApi实现方式》控制台程序作为Job时,需同步调用WebApi以确保获取返回结果后执行后续操作,否则会引发TaskCanceledException异常,同步处理可避免异... 目录同步调用WebApi方法Cls001类里面的写法总结控制台程序一般当作Job使用,有时候需要控制

Linux查询服务器系统版本号的多种方法

《Linux查询服务器系统版本号的多种方法》在Linux系统管理和维护工作中,了解当前操作系统的版本信息是最基础也是最重要的操作之一,系统版本不仅关系到软件兼容性、安全更新策略,还直接影响到故障排查和... 目录一、引言:系统版本查询的重要性二、基础命令解析:cat /etc/Centos-release详