有没有办法让 VSCode 不运行 c++程序如果编译失败怎么办?
在 VSCode 中,无论编译是否成功,C++ 的运行和调试启动任务都将运行程序(假设旧的可执行文件仍然存在)。我尝试通过使构建任务依赖于 rm 任务来解决问题,这将删除旧的可执行文件,确保编译错误不会让程序运行,但这有其自身的缺点,例如删除如果意外运行,则为没有扩展名的文件。我想知道是否有某种更聪明的方法可以做到这一点,而不需要制作更多的黑客解决方案,例如制作一个自定义脚本,该脚本仅在文件具有扩展名的情况下才运行整个考验(这仍然会留下大量的错误被发现)我确定)?
作为参考,我使用 g++ 进行编译。
In VSCode, Run and Debug launch task for C++ will run the program regardless of whether or not the compilation succeeded (given that an old executable is still present). I have tried to make a workaround by making the build task depend on the rm task, which would delete the old executable, ensuring that compilation error would not let the program run, but this comes with its own drawbacks, like say removing a file without an extension if it is accidentally run. I was wondering if there is some sort of smarter way to do this without making even more hacky solutions like making a custom script that will only run the whole ordeal if the file has an extension (which would still leave plenty of bugs to be found I'm sure)?
For reference, I use g++ for compilation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论