gpt4 book ai didi

C++ "Hello World.exe"崩溃 - 在命令提示符中使用时为 "Hello World.exe has stopped working."

转载 作者:可可西里 更新时间:2023-11-01 09:40:48 28 4
gpt4 key购买 nike

我已经开始学习 C++ 并编写了一个“Hello World”程序。当我尝试在命令提示符下运行它时,它崩溃并向我显示一条 Windows 消息“Hello World.exe 已停止工作。”。

代码:

#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 的路径。在我将 MinGW/bin 目录中的所有 dll 复制到 Hello World.exe 的文件夹后,程序运行顺利。因此,似乎无论需要那些 dll 的是什么,都无法正确访问它们。我想省去为我创建的每个项目复制 dll 的麻烦。有什么办法可以解决这个问题吗?

我对我的计算机和编程术语还不是很自信,所以描述可能看起来有点粗糙 - 仍然非常感谢帮助!

干杯!

最佳答案

以下instructions为我完成了工作,所以我将它们添加到这里以供将来引用,因为这个问题花了很长时间。

Prerequisites

  • 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

Installation Steps

  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 步 是解决问题的步骤。

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

关于C++ "Hello World.exe"崩溃 - 在命令提示符中使用时为 "Hello World.exe has stopped working.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20693240/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com