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

查看:51
本文介绍了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
";
    std::cin >> response;
    std::cout << "User: " << response;

    return(0);
}

我使用 Eclipse IDE 和 MinGW 作为编译器.我已经在环境变量中设置了MinGW/bin的路径.在我将 MinGW/bin 目录中的所有 dll 复制到 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!

干杯!

推荐答案

以下说明 为我完成了这项工作,因此我将它们添加到这里以供将来参考,因为这个问题需要相当长的时间.

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 或更高版本.
  • 日食

安装步骤

  1. 从 Oracle 安装 Java JRE.
  2. 安装 MinGW.在选择组件步骤中,选择C++编译器"和MSYS 基本系统"进行安装.
  3. 为 C++ 开发人员下载 Eclipse.
  4. 解压下载到您的下载文件夹的 Eclipse 存档.
  5. 打开在提取的 Eclipse 中找到的 Eclipse 应用程序文件夹.[2]
  6. 通过从文件和新建菜单.
  7. 在项目的可执行文件下选择Hello World C++ 项目"为您的新 C++ 项目的工具链键入和 MinGW GCC.类型一个项目名称,然后单击完成按钮.
  8. 添加-static-libgcc -static-libstdc++"作为新的链接器标志项目.此文本应添加到 Linker flags 字段,该字段可以在Project中右键新建Project找到资源管理器并单击属性.在项目属性下,展开 C/C++ Build 菜单并单击 Settings.在工具下设置选项卡,展开 MinGW C++ 链接器菜单并单击各种各样的.将文本添加到 Linker flags 字段,然后单击应用按钮.
  9. 点击 Project 菜单下的 Build Project,然后点击运行菜单.
  10. 通过查看控制台的输出.

请注意,步骤 8 是解决问题的步骤.

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

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

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