我已经开始学习 C++ 并编写了一个“Hello World”程序。当我尝试在命令提示符下运行它时,它崩溃并向我显示一条 Windows 消息“Hello World.exe 已停止工作。”。
Mã số:
#include
#include
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
- Install the Java JRE from Oracle.
- Install MinGW. During the Select Components step, select “C++ Compiler” and “MSYS Basic System” for installation.
- Download Eclipse for C++ Developers.
- Extract the Eclipse archive downloaded to your Downloads folder.
- Open the Eclipse application found in the extracted Eclipse folder.[2]
- Test your Eclipse install by creating a new C++ Project from the File and New menu.
- 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.
- 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.
- Click Build Project under the Project menu, then click Run under the Run menu.
- Confirm you have a functioning developer environment by viewing the output of the Console.
Xin lưu ý rằng第 8 步 是解决问题的步骤。
Để ý:您还应该将 freeglut.dll
复制到您的 .exe
所在的目录中。
Tôi là một lập trình viên xuất sắc, rất giỏi!