Visual Studio complains that .exe is not found when compiling for debug

微笑、不失礼 提交于 2020-05-26 04:25:22

问题


I have a very simple C++ application.

#include <stdio.h>
#include <iostream>

int main(int argc, char argv[]) {
  cout << "hi" << endl;
}

When I compile for the first time in debug mode, Visual Studio complains "Unable to start program ..\Debug\myprogram.exe. The system cannot find the file specified."

However, I think that this is obvious because I am compiling for the first time, right? This executable should not exist yet, so why is Visual Studio balking at compiling?

Thanks for your help.

Also, when I build, the following log appears:

When I build (Build->Build solution.), this log appears:

1>------ Build started: Project: print_digits, Configuration: Debug Win32 ------
1>Build started 12/23/2011 4:32:17 PM.
1>InitializeBuildStatus:
1>  Creating "Debug\print_digits.unsuccessfulbuild" because "AlwaysCreate" was specified.
1>FinalizeBuildStatus:
1>  Deleting file "Debug\print_digits.unsuccessfulbuild".
1>  Touching "Debug\print_digits.lastbuildstate".
1>
1>Build succeeded.
1>
1>Time Elapsed 00:00:00.08

It says build succeeded, but no executable is being built for some reason.


回答1:


A couple of problems here:

1) This error is about trying to RUN the program, not compile it:

"Unable to start program ..\Debug\myprogram.exe. The system cannot find the file specified."

2) Probably the reason it can't find the program is because it FAILED to COMPILE.

Here are the errors I got from your source:

tmp.cpp(5) : error C2065: 'cout' : undeclared identifier
tmp.cpp(5) : error C2297: '<<' : illegal, right operand has type 'char [3]'
tmp.cpp(5) : error C2065: 'endl' : undeclared identifier
tmp.cpp(6) : warning C4508: 'main' : function should return a value; 'void' return type assumed

You should be able to fix these particular errors if you add "using namespace std;"

Get a clean compile, and you should be able to run the debugger :)




回答2:


I had the same Issue. The problem was that my antivirus (in my case Avast) was automatically deleting the file on creation. And because I had Avast on silent mode it did not notice me about the deletion. So disabling the antivirus or setting up a exclusion rule helped in my case.




回答3:


Need to write after the includes

using namespace std; 



回答4:


I got a similar error when I didn't declare the libraries I was using correctly in "properties".

I think what I had to do was write the names of the .lib files in Properties/Linker/Input/Additional Dependencies and set the paths in "VC++ Directories". But you shouldn't get that problem with just stdio and iostream.




回答5:


Same problem had faced, after some RND finally i found the solution. Solution-Go to project properties->Security Tab->Uncheck "Enable ClickOnce Security settings".




回答6:


I have the same problem with Visual Studio 2015. If I have a solution with 2 projects and set the Output File in Linker->General to $(IntDir)$(TargetName)$(TargetExt) then it builds an .exe file (I have verified it exists), bit I cannot run it via Visual Studio. I currently don't have a solution to this problem, other than reverting back to $(OutDir). The current problem is that both projects produce the object files in $(IntDir) but I get two different .exe files in the same folder. Once I've tried to change the output location, I've been unable to get the debugger to execute the .exe file through Visual Studio, so I suspect I will need to edit the .sln or .vcxproj files to fix the problem. Unfortunately Visual Studio is buggy and might require editing the xml files directly in these situations, if these are the problems you are experiencing.



来源:https://stackoverflow.com/questions/8620939/visual-studio-complains-that-exe-is-not-found-when-compiling-for-debug

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