問題描述
我開始學習 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 或更高版本.
- 日食
安裝步驟
- 從 Oracle 安裝 Java JRE.
- 安裝 MinGW.在選擇組件步驟中,選擇C++編譯器"和MSYS 基本系統"進行安裝.
- 為 C++ 開發人員下載 Eclipse.
- 解壓下載到您的下載文件夾的 Eclipse 存檔.
- 打開在提取的 Eclipse 中找到的 Eclipse 應用程序文件夾.[2]
- 通過從文件和新建菜單.
- 在項目的可執行文件下選擇Hello World C++ 項目"為您的新 C++ 項目的工具鏈鍵入和 MinGW GCC.類型一個項目名稱,然后單擊完成按鈕.
- 添加-static-libgcc -static-libstdc++"作為新的鏈接器標志項目.此文本應添加到 Linker flags 字段,該字段可以在Project中右鍵新建Project找到資源管理器并單擊屬性.在項目屬性下,展開 C/C++ Build 菜單并單擊 Settings.在工具下設置選項卡,展開 MinGW C++ 鏈接器菜單并單擊各種各樣的.將文本添加到 Linker flags 字段,然后單擊應用按鈕.
- 點擊 Project 菜單下的 Build Project,然后點擊運行菜單.
- 通過查看控制臺的輸出.
請注意,步驟 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 已停止工作."在命令提示符中使用時的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!