C ++“Hello World.exe”崩溃 - “Hello World.exe已停止工作”。当在命令提示符中使用时 [英] C++ "Hello World.exe" crashes - "Hello World.exe has stopped working." when used in command prompt

查看:491
本文介绍了C ++“Hello World.exe”崩溃 - “Hello World.exe已停止工作”。当在命令提示符中使用时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始学习C ++,写了一个Hello World - 程序。当我试图运行它在命令提示符下,它崩溃,并给我一个Windows消息,说Hello World.exe已停止工作。

I've started learning C++ and wrote a "Hello World"-Program. When i try to run it in command prompt, it crashes and gives me a windows message saying "Hello World.exe has stopped working.".

代码:

#include <iostream>
#include <string>

int main()
{
    std::string response;

    std::cout << "Hallo Welt\n";
    std::cin >> response;
    std::cout << "User: " << response;

    return(0);
}



我使用Eclipse IDE和MinGW作为编译器。我已经在环境变量中设置MinGW / bin的路径。后我复制所有dll的形式MinGW / bin目录到Hello World.exe的文件夹中的程序工作顺利。所以,似乎无论是需要这些DLL不能正确访问它们。我想给我留下复制dll的每个项目我创建的麻烦。有什么办法可以解决这个问题吗?

I'm using Eclipse IDE and MinGW as compiler. I've already set the path of MinGW/bin in the environment variables. After i copied all dll's form the MinGW/bin directory into the folder of the Hello World.exe the program worked smoothly. So it seems that whatever it is that needs those dll's cannot access them properly. I'd like to spare me the hassle of copying the dll's for every project i create. Is there any way i could work around that?

我对计算机和编程术语还不是很有信心,所以说明看起来有些粗糙 - 非常感谢!

I'm not really confident about my computer and programming terminology yet so the description might seem a bit rough - help is still greatly appreciated!

干杯!

推荐答案

=https://orfe.princeton.edu/help/article-296>说明做了我的工作,所以我将它们添加到这里供将来参考,因为这个问题需要一些时间。

The following instructions did the work for me so I add them here for future reference as this problem took quite some time.


前提条件


  • Windows 7 64位,并应用所有当前软件更新。

  • MinGW 0.5-beta-20120426-1或更高版本。

  • Java JRE 1.7或更高版本。

  • Eclipse

  • Windows 7 64-bit with all current Software Updates applied.
  • MinGW 0.5-beta–20120426–1 or later.
  • Java JRE 1.7 or higher.
  • Eclipse

安装步骤
$ b

Installation Steps


  1. 从Oracle安装Java JRE。

  2. 安装MinGW。在选择组件步骤中,选择C ++
    Compiler和MSYS Basic System进行安装。

  3. 下载Eclipse for C ++ Developers。

  4. 提取下载到您的Downloads文件夹的Eclipse归档文件。

  5. 打开提取的Eclipse
    文件夹中的Eclipse应用程序。 li>通过从
    文件和新菜单创建一个新的C ++项目来测试Eclipse安装。

  6. 在项目的可执行文件下选择Hello World C ++项目
    类型和MinGW GCC用于新C ++项目的工具链。

  7. 为新的
    项目添加-static-libgcc -static-libstdc ++作为链接器标记。此文本应添加到链接器标记字段,
    可以通过右键单击项目
    资源管理器中的新项目并单击属性找到。在项目属性下,
    展开C / C ++ Build菜单,然后单击设置。在工具
    设置选项卡下,展开MinGW C ++链接器菜单,然后单击
    杂项。将文本添加到链接器标记字段,然后单击
    应用按钮。

  8. 单击项目菜单下的构建项目, b运行菜单。

  9. 通过查看控制台的
    输出确认您的开发者环境是否正常。

  1. Install the Java JRE from Oracle.
  2. Install MinGW. During the Select Components step, select "C++ Compiler" and "MSYS Basic System" for installation.
  3. Download Eclipse for C++ Developers.
  4. Extract the Eclipse archive downloaded to your Downloads folder.
  5. Open the Eclipse application found in the extracted Eclipse folder.[2]
  6. Test your Eclipse install by creating a new C++ Project from the File and New menu.
  7. Select "Hello World C++ Project" under Executable for the Project Type, and MinGW GCC for the Toolchain of your New C++ Project. Type a Project Name and click the Finish button.
  8. Add "-static-libgcc -static-libstdc++" as Linker flags for your new project. This text should be added to the Linker flags field, which can be found by right-clicking on the new Project in the Project Explorer and clicking on Properties. Under the Project Properties, expand the C/C++ Build menu and click on Settings. Under the Tool Settings tab, expand the MinGW C++ Linker menu and click on Miscellaneous. Add the text to the Linker flags field, then click the Apply button.
  9. Click Build Project under the Project menu, then click Run under the Run menu.
  10. Confirm you have a functioning developer environment by viewing the output of the Console.


请注意,步骤8 是解决问题的方法。

Please note that step 8 is the one that solves the problem.

注意:您还应该在 .exe 的目录中复制 freeglut.dll

Note: You should also copy freeglut.dll in the directory where your .exe is located.

这篇关于C ++“Hello World.exe”崩溃 - “Hello World.exe已停止工作”。当在命令提示符中使用时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆