Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

windows - C++ "Hello World.exe" crashes - "Hello World.exe has stopped working." when used in command prompt

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.".

Code:

#include <iostream>
#include <string>

int main()
{
    std::string response;

    std::cout << "Hallo Welt
";
    std::cin >> response;
    std::cout << "User: " << response;

    return(0);
}

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!

Cheers!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The following instructions did the work for me so I add them here for future reference as this problem took quite some time.

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.

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

Note: You should also copy freeglut.dll in the directory where your .exe is located.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...