[英]VS Code - How to run unchanged c++ files without building them again
I've managed to configure vs code to build and run c++ files using tutorials on their official website and it worked fine, but it rebuilds the files every time I hit F5 even if the files were unchanged.我已经设法使用他们官方网站上的教程配置 vs 代码来构建和运行 c++ 文件,它运行良好,但即使文件没有改变,每次我点击 F5 时它都会重建文件。
What I want is to run the unchanged files without rebuild them.我想要的是运行未更改的文件而不重建它们。 I tried to write another task to "just-run-without-rebuild" but didn't know how to switch between this task and the build task, I searched the internet but no solutions.我试图编写另一个任务来“只运行而不重建”,但不知道如何在此任务和构建任务之间切换,我在互联网上搜索但没有解决方案。
my task.json is this:我的 task.json 是这样的:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": ["-std=c++11", "starter.cpp"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
and launch.json is:和 launch.json 是:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.exe",
"cwd": "${workspaceRoot}",
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:/mingw64/bin/gdb.exe",
"preLaunchTask": "build",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
So basically the "preLaunchTask" is running the "build" task every time it runs, but I want something like this:所以基本上“preLaunchTask”每次运行时都会运行“构建”任务,但我想要这样的东西:
if (cpp_file is unchanged) then
"preLaunchTask" : None
else
"preLaunchTask" : "build"
Thanks in advance.提前致谢。
What I did was assign the 'F4' key for Run Task, then the 'F5' key for Run Without Debugging and the 'Ctrl + F5' key combination for Start Debugging.我所做的是为运行任务分配“F4”键,然后为“无调试运行”分配“F5”键,为“开始调试”分配“Ctrl + F5”组合键。
My tasks.json:我的tasks.json:
{
"tasks": [
{
"type": "shell",
"label": "C/C++",
"command": "C:\\Users\\Kamat\\Desktop\\Programacion\\C++\\Compiler\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"group": {
"kind": "build",
"isDefault": true
}
}
],
"version": "2.0.0"
}
My launch.json:我的launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Users\\Kamat\\Desktop\\Programacion\\C++\\Compiler\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Habilitar la impresión con sangría para gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": null
}
]
}
If you find a way to do this process automatically let me know, thank you.如果您找到自动执行此过程的方法,请告诉我,谢谢。
I'm still a beginner at this and I can make some mistakes, but this worked well for me, I hope it works for you too.我仍然是这方面的初学者,我可能会犯一些错误,但这对我来说很有效,我希望它也适用于你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.