简体   繁体   English

VS Code - 如何在不重新构建的情况下运行未更改的 C++ 文件

[英]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.

相关问题 如何设置VS Code以在OSX中构建,运行和调试简单的C ++文件? - How to setup VS Code for Building, Running and Debugging simple C++ files in OSX? 无法在 VS Code 上使用代码运行器运行 C++ 文件 - Unable to run C++ files using code runner on VS Code 如何在 VS Code 中轻松编译和运行 C++ 代码? - How to compile and run C++ code in VS Code easily? 使用 Ctrl + Shift + B 构建时,VS Code 终端不运行 C++ 程序 - VS Code terminal doesn't run a C++ program when building with Ctrl + Shift + B 如何从终端 VS Code 运行 C++ 程序 - How to run C++ program from terminal VS Code 如何在不关闭它们的情况下切换fstream文件(同时输出文件) - C ++ - How can I switch between fstream files without closing them (Simultaneous output files) - C++ 如何从方法返回不可变参数,未更改,并且在c ++中没有副本? - How do I return an immutable parameter from a method, unchanged, and without a copy in c++? (C++) 如何修改/使用数据结构,以便我们可以一次又一次地使用它们? - (C++) How to modify/use data structures such that we can use them again and again? 如何在C ++中将运行时类型鉴别器映射到模板实例(无需手动枚举它们)? - How in C++ to map run-time type discriminators to template instances (without manually enumerating them all)? Visual Studio 中是否有一个选项可以简单地查看文件如何包含在我的 C++ 代码中而无需构建? - Is there an option in Visual Studio that provides a simple view of how a file is included in my C++ code without building?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM