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

相关文章

MySQL查询JSON数组字段包含特定字符串的方法

《MySQL查询JSON数组字段包含特定字符串的方法》在MySQL数据库中,当某个字段存储的是JSON数组,需要查询数组中包含特定字符串的记录时传统的LIKE语句无法直接使用,下面小编就为大家介绍两种... 目录问题背景解决方案对比1. 精确匹配方案(推荐)2. 模糊匹配方案参数化查询示例使用场景建议性能优

Visual Studio 2022 编译C++20代码的图文步骤

《VisualStudio2022编译C++20代码的图文步骤》在VisualStudio中启用C++20import功能,需设置语言标准为ISOC++20,开启扫描源查找模块依赖及实验性标... 默认创建Visual Studio桌面控制台项目代码包含C++20的import方法。右键项目的属性:

Linux中SSH服务配置的全面指南

《Linux中SSH服务配置的全面指南》作为网络安全工程师,SSH(SecureShell)服务的安全配置是我们日常工作中不可忽视的重要环节,本文将从基础配置到高级安全加固,全面解析SSH服务的各项参... 目录概述基础配置详解端口与监听设置主机密钥配置认证机制强化禁用密码认证禁止root直接登录实现双因素

在Linux终端中统计非二进制文件行数的实现方法

《在Linux终端中统计非二进制文件行数的实现方法》在Linux系统中,有时需要统计非二进制文件(如CSV、TXT文件)的行数,而不希望手动打开文件进行查看,例如,在处理大型日志文件、数据文件时,了解... 目录在linux终端中统计非二进制文件的行数技术背景实现步骤1. 使用wc命令2. 使用grep命令

解决未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4‘问题

《解决未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4‘问题》:本文主要介绍解决未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4... 目录未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4‘打开pom.XM

Linux如何快速检查服务器的硬件配置和性能指标

《Linux如何快速检查服务器的硬件配置和性能指标》在运维和开发工作中,我们经常需要快速检查Linux服务器的硬件配置和性能指标,本文将以CentOS为例,介绍如何通过命令行快速获取这些关键信息,... 目录引言一、查询CPU核心数编程(几C?)1. 使用 nproc(最简单)2. 使用 lscpu(详细信

linux重启命令有哪些? 7个实用的Linux系统重启命令汇总

《linux重启命令有哪些?7个实用的Linux系统重启命令汇总》Linux系统提供了多种重启命令,常用的包括shutdown-r、reboot、init6等,不同命令适用于不同场景,本文将详细... 在管理和维护 linux 服务器时,完成系统更新、故障排查或日常维护后,重启系统往往是必不可少的步骤。本文

基于Linux的ffmpeg python的关键帧抽取

《基于Linux的ffmpegpython的关键帧抽取》本文主要介绍了基于Linux的ffmpegpython的关键帧抽取,实现以按帧或时间间隔抽取关键帧,文中通过示例代码介绍的非常详细,对大家的学... 目录1.FFmpeg的环境配置1) 创建一个虚拟环境envjavascript2) ffmpeg-py

nginx启动命令和默认配置文件的使用

《nginx启动命令和默认配置文件的使用》:本文主要介绍nginx启动命令和默认配置文件的使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录常见命令nginx.conf配置文件location匹配规则图片服务器总结常见命令# 默认配置文件启动./nginx

Linux脚本(shell)的使用方式

《Linux脚本(shell)的使用方式》:本文主要介绍Linux脚本(shell)的使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录概述语法详解数学运算表达式Shell变量变量分类环境变量Shell内部变量自定义变量:定义、赋值自定义变量:引用、修改、删