C++ Visual Studio 抱怨编译调试时找不到 .exe
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8620939/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Studio complains that .exe is not found when compiling for debug
提问by dangerChihuahua007
I have a very simple C++ application.
我有一个非常简单的 C++ 应用程序。
#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."
当我在调试模式下第一次编译时,Visual Studio 抱怨“无法启动程序 ..\Debug\myprogram.exe。系统找不到指定的文件。”
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?
但是,我认为这是显而易见的,因为我是第一次编译,对吗?这个可执行文件不应该存在,那么为什么 Visual Studio 在编译时犹豫不决?
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.
它说构建成功,但由于某种原因没有构建可执行文件。
采纳答案by paulsm4
A couple of problems here:
这里有几个问题:
1) This error is about trying to RUN the program, not compile it:
1) 这个错误是关于尝试运行程序,而不是编译它:
"Unable to start program ..\Debug\myprogram.exe. The system cannot find the file specified."
“无法启动程序 ..\Debug\myprogram.exe。系统找不到指定的文件。”
2) Probably the reason it can't find the program is because it FAILED to COMPILE.
2) 可能找不到程序的原因是它编译失败。
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;"
如果您添加“using namespace std;”,您应该能够修复这些特定错误。
Get a clean compile, and you should be able to run the debugger :)
得到一个干净的编译,你应该能够运行调试器:)
回答by Flurin
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.
我遇到过同样的问题。问题是我的防病毒软件(就我而言是 Avast)在创建时自动删除了该文件。而且因为我在静音模式下使用 Avast,所以它没有注意到我的删除。因此,禁用防病毒软件或设置排除规则对我有帮助。
回答by user1022370
Need to write after the includes
需要写在includes之后
using namespace std;
回答by Student
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.
我认为我必须做的是在 Properties/Linker/Input/Additional Dependencies 中写入 .lib 文件的名称,并在“VC++ 目录”中设置路径。但是您不应该只使用 stdio 和 iostream 就遇到这个问题。
回答by J R B
Same problem had faced, after some RND finally i found the solution. Solution-Go to project properties->Security Tab->Uncheck "Enable ClickOnce Security settings".
遇到了同样的问题,经过一些 RND 后,我终于找到了解决方案。解决方案-转到项目属性->安全选项卡->取消选中“启用 ClickOnce 安全设置”。
回答by J R B
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.
我在 Visual Studio 2015 中遇到了同样的问题。如果我有一个包含 2 个项目的解决方案并将 Linker->General 中的输出文件设置为 $(IntDir)$(TargetName)$(TargetExt) 然后它会构建一个 .exe 文件(我已验证它存在),有点我无法通过 Visual Studio 运行它。除了恢复到 $(OutDir) 之外,我目前没有解决此问题的方法。当前的问题是两个项目都在 $(IntDir) 中生成目标文件,但我在同一文件夹中得到两个不同的 .exe 文件。一旦我尝试更改输出位置,我就无法让调试器通过 Visual Studio 执行 .exe 文件,所以我怀疑我需要编辑 .sln 或 .vcxproj 文件来解决问题。不幸的是,Visual Studio 有问题,在这些情况下可能需要直接编辑 xml 文件,