問(wèn)題描述
我開(kāi)始學(xué)習(xí) C++ 并編寫了一個(gè)Hello World"程序.當(dāng)我嘗試在命令提示符下運(yùn)行它時(shí),它崩潰并給我一條 Windows 消息,說(shuō)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 作為編譯器.我已經(jīng)在環(huán)境變量中設(shè)置了MinGW/bin的路徑.在我將 MinGW/bin 目錄中的所有 dll 復(fù)制到 Hello World.exe 的文件夾中后,程序運(yùn)行順利.因此,似乎需要這些 dll 的任何東西都無(wú)法正確訪問(wèn)它們.我想省去為我創(chuàng)建的每個(gè)項(xiàng)目復(fù)制 dll 的麻煩.有什么辦法可以解決這個(gè)問(wèn)題嗎?
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?
我對(duì)我的計(jì)算機(jī)和編程術(shù)語(yǔ)還不是很自信,所以描述可能有點(diǎn)粗略 - 仍然非常感謝幫助!
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!
干杯!
推薦答案
以下說(shuō)明 為我完成了這項(xiàng)工作,因此我將它們添加到這里以供將來(lái)參考,因?yàn)檫@個(gè)問(wèn)題需要相當(dāng)長(zhǎng)的時(shí)間.
The following instructions did the work for me so I add them here for future reference as this problem took quite some time.
先決條件
- 應(yīng)用了所有當(dāng)前軟件更新的 Windows 7 64 位.
- MinGW 0.5-beta–20120426–1 或更高版本.
- Java JRE 1.7 或更高版本.
- 日食
安裝步驟
- 從 Oracle 安裝 Java JRE.
- 安裝 MinGW.在選擇組件步驟中,選擇C++編譯器"和MSYS 基本系統(tǒng)"進(jìn)行安裝.
- 為 C++ 開(kāi)發(fā)人員下載 Eclipse.
- 解壓下載到您的下載文件夾的 Eclipse 存檔.
- 打開(kāi)在提取的 Eclipse 中找到的 Eclipse 應(yīng)用程序文件夾.[2]
- 通過(guò)從文件和新建菜單.
- 在項(xiàng)目的可執(zhí)行文件下選擇Hello World C++ 項(xiàng)目"為您的新 C++ 項(xiàng)目的工具鏈鍵入和 MinGW GCC.類型一個(gè)項(xiàng)目名稱,然后單擊完成按鈕.
- 添加-static-libgcc -static-libstdc++"作為新的鏈接器標(biāo)志項(xiàng)目.此文本應(yīng)添加到 Linker flags 字段,該字段可以在Project中右鍵新建Project找到資源管理器并單擊屬性.在項(xiàng)目屬性下,展開(kāi) C/C++ Build 菜單并單擊 Settings.在工具下設(shè)置選項(xiàng)卡,展開(kāi) MinGW C++ 鏈接器菜單并單擊各種各樣的.將文本添加到 Linker flags 字段,然后單擊應(yīng)用按鈕.
- 點(diǎn)擊 Project 菜單下的 Build Project,然后點(diǎn)擊運(yùn)行菜單.
- 通過(guò)查看控制臺(tái)的輸出.
請(qǐng)注意,步驟 8 是解決問(wèn)題的步驟.
Please note that step 8 is the one that solves the problem.
注意:您還應(yīng)該將freeglut.dll
復(fù)制到您的.exe
所在的目錄中.
Note: You should also copy freeglut.dll
in the directory where your .exe
is located.
這篇關(guān)于C++“Hello World.exe"崩潰 - “Hello World.exe 已停止工作."在命令提示符中使用時(shí)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!