Eclipse - C++ hello world 项目的错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6017890/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 19:21:13  来源:igfitidea点击:

Eclipse - C++ hello world project's error

c++eclipsewindows-7binary

提问by Masoud

I am using a 64-bit Winodws 7. I've downloaded a CDTEclipseand have downloaded MinGW. After that, I created a c++ hello world project. This is the code:

我使用的是 64 位 Winodws 7。我已经下载了一个CDTEclipse并下载了MinGW. 之后,我创建了一个 C++ hello world 项目。这是代码:

#include <iostream>
using namespace std;

int main() {
    cout << "!!!Hello World!!!" << endl; // This is supposed to print "Hello World!!!"
    return 0;
}

But when I want to run it, this error pops up: "Launch failed. Binary not found."

但是当我想运行它时,会弹出这个错误:“Launch failed Binary not found..”

Any help would be highly welcomed.

任何帮助将受到高度欢迎。

回答by Teimpz

You have to "Build" your project before you can "Run" it. When using Eclipse for Java, you simply click the "Run" icon, then Eclipse will automaticly compile your program and then run it. With C++ however, this is for whatever reason not the case. Instead of just clicking the "Run" icon, you need to click the "Build" icon first. This is where Eclipse will create a makefile and compile your program. Then you can run it by clicking the "Run" icon.

您必须先“构建”您的项目,然后才能“运行”它。使用 Eclipse for Java 时,您只需单击“运行”图标,Eclipse 将自动编译您的程序,然后运行它。然而,对于 C++,无论出于何种原因,情况并非如此。您需要先单击“构建”图标,而不是仅单击“运行”图标。这是 Eclipse 将创建一个 makefile 并编译您的程序的地方。然后您可以通过单击“运行”图标来运行它。

I hope this solves your problem.

我希望这能解决你的问题。

回答by Roddy

Has eclipse built the EXE file correctly for you? Look for helloworld.exe or whatever, and try running it from a Windows Command prompt.

eclipse 是否为您正确构建了 EXE 文件?查找 helloworld.exe 或其他任何内容,然后尝试从 Windows 命令提示符运行它。

If not, then you've got a problem with your build. Build it again and check for errors.

如果没有,那么你的构建有问题。再次构建它并检查错误。

If the EXE file is there, but cannot be run from within Eclipse then check that the PE Windows Binary Parseris enabled for your project.

如果 EXE 文件在那里,但不能从 Eclipse 中运行,则检查是否为您的项目启用了PE Windows 二进制解析器

UPDATE: To fix "Unresolved Inclusion" errors, see here.In particular, try this:

更新:要修复“未解决的包含”错误,请参见此处。特别是,试试这个:

  1. Right-click on the probject and select "Properties"
  2. Go to "C/C++ General" -> "Paths and Symbols" and select "Includes" tab
  3. Select "GNU C++"
  4. Press on "Add..."
  5. Look for the folder "C:\dev\eclipse\mingw\lib\gcc\mingw32\4.4.1-dw2\include\c++" or similar
  1. 右键单击对象并选择“属性”
  2. 转到“C/C++ General”->“Paths and Symbols”并选择“Includes”选项卡
  3. 选择“GNU C++”
  4. 按“添加...”
  5. 查找文件夹“C:\dev\eclipse\mingw\lib\gcc\mingw32\4.4.1-dw2\include\c++”或类似的

UPDATESee also this link:

更新见此链接:

http://wiki.eclipse.org/CDT/User/FAQ#I_am_using_a_non_gnu_compiler_and_I_get_the_following_messages:_.22Error_launching_external_scanner_info_generator_.28gcc_-E_-P_-v_-dD.22_and_.22File_not_indexed_because_it_was_not_built_.22._How_do_I_get_rid_of_them.3F

http://wiki.eclipse.org/CDT/User/FAQ#I_am_using_a_non_gnu_compiler_and_I_get_the_following_messages:_.22Error_launching_external_scanner_info_generator_.28gcc_-E_-P_-v_-dD.22_and_the_now_notrid_file222_and_the_notrid_ofm_get_the_notid_file_ofm_get_of_built_file_file_file_file_file_file_files_of_122_3_1_3_notrid_file_file_files_

回答by IcedDante

The problem is because you Windows is 64 bit and Eclipse just sort of chooses to ignore executables in this format without reporting any error. Pretty convenient, huh? Try this to fix it:

问题是因为您的 Windows 是 64 位,而 Eclipse 只是选择忽略这种格式的可执行文件而不报告任何错误。很方便吧?试试这个来修复它:

Right-click your project -> Properties -> expand "MinGW C++ Liker" in the right side pane and select the Miscellaneousoption

右键单击您的项目 -> 属性 -> 在右侧窗格中展开“MinGW C++ Liker”并选择Miscellaneous选项

Under "Other options" you will add a new option:

在“其他选项”下,您将添加一个新选项:

-arch=i386

Rebuild your application, refresh, and you should see a Binariesfolder that contains your executable. You can run it by going to Run As -> Local C/C++ Application

重新构建您的应用程序,刷新,您应该会看到一个包含可执行文件的Binaries文件夹。您可以通过转到运行方式 -> 本地 C/C++ 应用程序来运行它

回答by Omkar

First check the toolchain selected,while creating the new c++ project.It should be MinGW as you have stated,(hope you have made the entries in the environmental variables).Write the code .press ctrl+b to build the workspace. Rt click the project and select clean project.press f5 to refresh.then ctrl+f11 to run your prg.Hope this helps..

首先检查选择的工具链,同时创建新的c++项目。它应该是你所说的MinGW,(希望你已经在环境变量中输入了)。编写代码。按ctrl+b构建工作区。Rt 单击项目并选择清理项目。按 f5 刷新。然后 ctrl+f11 运行您的 prg。希望这有帮助。

回答by Rose Perrone

Make sure you select the correct Toolchain when you create the project.

确保在创建项目时选择正确的工具链。

enter image description here

enter image description here

回答by Selvadurai Handeeban

This happens due to windows execution permission (I assume that you're running eclipse from an external drive or from another partition), if you run eclipse as an administrator you will be able to debug your application without problems..

这是由于 Windows 执行权限造成的(我假设您是从外部驱动器或另一个分区运行 eclipse),如果您以管理员身份运行 eclipse,您将能够毫无问题地调试您的应用程序。