简体   繁体   English

“运行C ++程序时,系统无法找到指定的文件”

[英]“The system cannot find the file specified” when running C++ program

I installed Visual Studio 2010. I wrote a simple code which I'm sure is correct but unfortunately, when I run the code, I get the error below. 我安装了Visual Studio 2010.我编写了一个简单的代码,我确信它是正确的但不幸的是,当我运行代码时,我得到下面的错误。

Here is my code: 这是我的代码:

#include<iostream>
using namespace std;
int main (){ 
  cout <<"Hello StackOverFlow ;)";
  return 0;
}

And here is the error: 这是错误:

Unable to start program 'C:\\Users\\Soheil\\Desktop\\New folder\\sam\\Debug\\sam.exe The system cannot find the file specified 无法启动程序'C:\\ Users \\ Soheil \\ Desktop \\ New folder \\ sam \\ Debug \\ sam.exe系统找不到指定的文件

Would you help me solve the issue? 你能帮我解决这个问题吗? Should I define the project in a specific directory? 我应该在特定目录中定义项目吗? I've spent a ton of hours to solve this issue and have not had any success yet. 我花了很多时间来解决这个问题,但还没有取得任何成功。

This is a first step for somebody that is a beginner. 这是初学者的第一步。 Same thing happened to me: 同样的事情发生在我身上:

Look in the Solution Explorer box to the left. 查看左侧的“ 解决方案资源管理器”框。 Make sure that there is actually a .cpp file there. 确保那里有一个.cpp文件。 You can do the same by looking the .cpp file where the .sln file for the project is stored. 您可以通过查看存储项目的.sln文件的.cpp文件来执行相同操作。 If there is not one, then you will get that error. 如果没有,那么你会得到那个错误。

When adding a cpp file you want to use the Add new item icon. 添加cpp文件时,您要使用“ 添加新项目”图标。 (top left with a gold star on it, hover over it to see the name) For some reason Ctrl+N does not actually add a .cpp file to the project. (左上角有一颗金色星星,将鼠标悬停在它上面以查看名称)由于某种原因, Ctrl + N实际上并没有将.cpp文件添加到项目中。

Encountered the same issue, after downloading a project, in debug mode. 在下载项目后,在调试模式下遇到相同的问题。 Searched for hours without any luck. 搜索了几个小时没有任何运气。 Following resolved my problem; 以下解决了我的问题;

Project Properties -> Linker -> Output file -> $(OutDir)$(TargetName)$(TargetExt) 项目属性 - >链接器 - >输出文件 - > $(OutDir)$(TargetName)$(TargetExt)

It was previously pointing to a folder that MSVS wasn't running from whilst debugging mode. 它之前指向MSVS在调试模式下没有运行的文件夹。

EDIT: soon as I posted this I came across: unable to start "program.exe" the system cannot find the file specified vs2008 which explains the same thing. 编辑:很快我发布这个我遇到: 无法启动“program.exe”系统找不到指定vs2008的文件 ,这解释了同样的事情。

I have recently not used VS 2010. 我最近没有使用VS 2010。

Does your application really build correctly? 您的应用程序是否真的正确构建 To get more control in VS 2010 C++ Express , you can check menu item " Expert Settings " under Tools>Settings to get a Build' menu . 要在VS 2010 C++ Express获得更多控制权,可以在Tools>Settings下检查菜单项“ Expert Settings ”以获取“ Build' menu
After clicking Build->Build Solution (or Rebuild ), you may verify in Output window ( View->Outout ), if your application is compiling and linking correctly. 单击Build->Build Solution (或Rebuild )后,如果您的应用程序正在编译和链接,您可以在Output窗口( View->Outout )中进行验证。

Sources : 资料来源:

Hope it helps. 希望能帮助到你。

I know this is an old thread, but for any future visitors, the cause of this error is most likely because you haven't built your project from Build > Build Solution . 我知道这是一个旧线程,但是对于任何未来的访问者来说,这个错误的原因很可能是因为你还没有从Build > Build Solution构建你的项目。 The reason you're getting this error when you try to run your project is because Visual Studio can't find the executable file that should be produced when you build your project. 尝试运行项目时出现此错误的原因是Visual Studio无法找到构建项目时应生成的可执行文件。

As others have mentioned, this is an old thread and even with this thread there tends to be different solutions that worked for different people. 正如其他人所提到的,这是一个老线程,即使有这个主题,也往往会有不同的解决方案适用于不同的人。 The solution that worked for is as follows: 适用的解决方案如下:

Right Click Project Name > Properties
Linker > General 
Output File > $(OutDir)$(TargetName)$(TargetExt) as indicated by @ReturnVoid
Click Apply

For whatever reason this initial correction didn't fix my problem (I'm using VS2015 Community to build c++ program). 无论出于何种原因,这个初步修正并没有解决我的问题(我正在使用VS2015社区来构建c ++程序)。 If you still get the error message try the following additional steps: 如果仍然收到错误消息,请尝试以下附加步骤:

Back in Project > Properties > Linker > General > Output File > 

You'll see the previously entered text in bold 您将看到以前以粗体显示的文本

Select Drop Down > Select "inherit from parent or project defaults"
Select Apply

Previously bold font is no longer bold 以前的粗体字体不再是粗体

Build > Rebuild > Debug

It doesn't make since to me to require these additional steps in addition to what @ReturnVoid posted but...what works is what works...hope it helps someone else out too. 除了@ReturnVoid发布的内容之外,我不需要这些额外的步骤,但......有效的是什么有用......希望它也可以帮助其他人。 Thanks @ReturnVoid 谢谢@ReturnVoid

I know this thread is 1 year old but I hope this helps someone, my problem was that I needed to add: 我知道这个帖子是1岁但我希望这对某人有帮助,我的问题是我需要添加:

    #include "stdafx.h"

to my project ( on the first line ), this seems to be the case most of the time! 到我的项目( 在第一行 ),这似乎是大多数情况下的情况!

For me, I didn't have my startup project set in Solution Explorer. 对我来说,我没有在解决方案资源管理器中设置我的启动项目。

Go to Solution Explorer on the left of VS, right click your unit test project, and choose "set as startup project". 转到VS左侧的解决方案资源管理器,右键单击您的单元测试项目,然后选择“设置为启动项目”。

I had just ported my code to a new workspace, and forgot that when I opened the project in VS in the solution there, that I needed to re-set my startup project. 我刚刚将我的代码移植到一个新的工作区,忘记了当我在VS中的解决方案中打开项目时,我需要重新设置我的启动项目。

I came across this problem and none of these solution worked 100% 我遇到了这个问题,这些解决方案都没有100%工作

In addition to ReturnVoid's answer which suggested the change 除了ReturnVoid的答案之外,还提出了改变

Project Properties -> Linker -> Output file -> $(OutDir)$(TargetName)$(TargetExt) 项目属性 - >链接器 - >输出文件 - > $(OutDir)$(TargetName)$(TargetExt)

I needed to changed 我需要改变

Project Properties -> C/C++ -> Debug Information Format -> /Zi 项目属性 - > C / C ++ - >调试信息格式 - > /Zi

This field was blank for me, changing the contents to /Zi (or /Z7 or /ZI if those are the formats you want to use) allowed me to debug 这个字段对我来说是空白的,将内容更改为/Zi (或/Z7/ZI如果这些是您要使用的格式)允许我调试

I got this problem during debug mode and the missing file was from a static library I was using. 我在调试模式下遇到了这个问题,丢失的文件来自我正在使用的静态库。 The problem was solved by using step over instead of step into during debugging 通过在调试期间使用步骤而不是步进来解决问题

if vs2010 installed correctly 如果vs2010安装正确

check file type (.cpp) 检查文件类型(.cpp)

just build it again It will automatically fix,, ( if you are using VS 2010 ) 再次构建它会自动修复,(如果你使用的是VS 2010)

I had a same problem and i could fixed it! 我有同样的问题,我可以解决它! you should add C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.1A\\Lib\\x64 for 64 bit system / C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.1A\\Lib for 32 bit system in property manager-> Linker-> General->Additional library Directories 你应该为64位系统添加C:\\ Program Files(x86)\\ Microsoft SDKs \\ Windows \\ v7.1A \\ Lib \\ x64 / C:\\ Program Files(x86)\\ Microsoft SDKs \\ Windows \\ v7.1A \\ Lib for 32属性管理器中的位系统 - >链接器 - >常规 - >附加库目录

maybe it can solve the problem of somebody in the future! 也许它可以解决将来某人的问题!

Since this thread is one of the top results for that error and has no fix yet, I'll post what I found to fix it, originally found in this thread: Build Failure? 由于此线程是该错误的最佳结果之一,并且还没有修复,我将发布我发现的修复它,最初在此线程中找到: 构建失败? "Unable to start program... The system cannot find the file specificed" which lead me to this thread: Error 'LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt' after installing Visual Studio 2012 Release Preview “无法启动程序......系统无法找到指定的文件” ,这导致我进入此线程: 错误'LINK:致命错误LNK1123:转换为COFF期间失败:文件无效或损坏'安装Visual Studio 2012 Release Preview后

Basically all I did is this: Project Properties -> Configuration Properties -> Linker (General) -> Enable Incremental Linking -> "No (/INCREMENTAL:NO)" 基本上我所做的就是: Project Properties -> Configuration Properties -> Linker (General) -> Enable Incremental Linking -> "No (/INCREMENTAL:NO)"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Visual C ++ 2010错误。 运行LibICP时,系统找不到指定的文件 - Visual C++ 2010 error. The system cannot find the file specified when running LibICP 无法启动程序:系统找不到指定的文件。 (C ++ BTW) - Unable to Start Program: The system cannot find the file specified. (C++ BTW) C ++错误:“无法启动程序&#39;filepath.exe&#39;,系统找不到指定的文件 - C++ error: "Unable to start program 'filepath.exe' The system cannot find the file specified C++,系统无法执行指定的程序 - C++, The system cannot execute the specified program 错误:无法启动程序“*.exe”系统找不到指定的文件 - Error: unable to start program "*.exe" the system cannot find the file specified C ++ Mingw32 CreateProcess()失败,错误代码为2:系统找不到指定的文件 - C++ Mingw32 CreateProcess() failed with error code 2: The system cannot find the file specified c++ filesystem系统找不到指定的路径 - c++ filesystem The system cannot find the path specified 视觉工作室。 无法启动程序 &#39;&#39; 系统找不到指定的文件 - Visual Studio. Unable to start program '' The system cannot find the file specified Visual Studio:无法启动程序,系统找不到指定的文件 Visual Studio 错误? - Visual Studio: Unable to start program, the system cannot find the file specified visual studio error? “+1 超载 --- Function 未找到“...”的定义”以及“无法启动程序。系统找不到指定的文件” - "+1 Overload --- Function definition for '...' not found" Along With "Unable to start program. The system cannot find the file specified"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM