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

查看:247
本文介绍了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的形式复制到MinnetWorld的文件夹MinGW / bin目录下,程序运行顺利。所以看来,无论是需要那些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!

干杯!

推荐答案

以下说明为我做了工作,所以我把它们添加到这里供将来参考,因为这个问题花了很多时间。

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

安装步骤


  1. 从Oracle安装Java JRE。

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

  3. 下载Eclipse for C ++ Developers。

  4. 解压缩下载到您的Downloads文件夹的Eclipse文件夹。

  5. 打开Eclipse提取的Eclipse
    文件夹中的Eclipse应用程序[2]

  6. 通过从
    文件和新菜单创建一个新的C ++项目来测试Eclipse安装。

  7. 在项目的可执行文件下选择Hello World C ++ Project
    类型和MinGW GCC为您的新C ++项目的工具链。键入
    一个项目名称,然后单击完成按钮。

  8. 将-static-libgcc -static-libstdc ++添加为新
    项目的链接器标志。此文本应添加到链接器标志字段中,通过右键单击Project
    Explorer中的新项目并单击属性,可以找到
    。在项目属性下,
    展开C / C ++生成菜单,然后单击设置。在工具
    设置选项卡下,展开MinGW C ++链接器菜单,然后单击
    其他。将文本添加到链接器标志字段,然后单击
    应用按钮。

  9. 单击项目菜单下的构建项目,然后单击$ b $下的运行b运行菜单。

  10. 通过查看控制台的
    输出确认您的开发人员环境正常。

  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天全站免登陆