When debugging a visual c+ program, the file specified can't be executed

99封情书 提交于 2019-12-25 06:29:04

问题


I made a simple hello world program. I clicked on "Start Debugging" and the window showed "Project is out of date. Would you like to build it?" As I click on "yes", the next window shows "There were build errors. Would you like to continue and run the last successful build?". I choose yes again, and it shows this window: (attached screenshot)enter image description here


回答1:


There were build errors. Would you like to continue and run the last successful build?

The only correct answer to that question is "No". If you clicked "Debug", you obviously want to debug the current version of the source, not some stale old version that won't match what you're seeing in the editor.

Disable this nonsense message in Tools → Options → Projects and Solutions → Build and Run. For "On Run, when projects are out of date", set it to "Always build". For "On Run, when build or deployment errors occur", set it to "Do not launch".

I cannot think of a reason why you ever want the other options as default settings. If you want to launch an old, stale build, you can always do so manually.

I choose yes again, and it shows this window: "The system cannot find the file specified."

Yet another reason why this is a stupid setting. The second one in particular, the one that controls Run behavior when build errors occur.

What happens is, when you tried to build the project, the first step was to do a clean, which effectively means delete the old files. With the old files gone, it kicks off a build. The build fails, you get an error. You ask it to ignore the error and run an old version. But wait! The old version got deleted at the start of the build, so it no longer exists!

If a build fails, return to the IDE, fix the errors, and then relaunch to rebuild.


Bonus: The build error that you're getting is "fatal error C1010", which is a rather silly error that can be very confusing to those unaccustomed to Visual Studio. Basically, what it's telling you is that because you are using precompiled headers (the default for new projects), the very first line in every source file needs to be the inclusion of your precompiled header. By default, it is named stdafx.h, so the first line in your code file should be:

#include "stdafx.h"

This should go before you include the system header <iostream>. The precompiled header must be included at the very top of the file, or you'll get a build error.

If you do not like that, then you can turn off precompiled headers:

  1. Right-click on your project in the Solution Explorer, and choose Properties.
  2. At the top, click the "Configuration" combobox and select "All Configurations".
  3. Expand "C/C++" in the tree view, and select "Precompiled Headers".
  4. Set the top option, "Precompiled Header", to "Not Using Precompiled Headers".



回答2:


Sorry: your last successful build was deleted earlier - possibly as a result of an attempted compile/link. You need to fix the source code that you've got now before you've got anything to debug...




回答3:


It seems to appear that some .dll files are missing for the debug mode for many users.

You don't need to run the debug mode for this, if your program works on normal running, then let it run.

I also can see that you wrote void main() but in C++ the good syntax is int main() and terminated by a return 0; instruction. By the way, think about letting at least a space between #include and the libraries like <iostream> here.



来源:https://stackoverflow.com/questions/37810571/when-debugging-a-visual-c-program-the-file-specified-cant-be-executed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!