How to compile and run C++ with MinGW using Eclipse and CDT?

96,725

Solution 1

Does Setting up Eclipse CDT on Windows, Linux/Unix, Mac OS X work for you?

Solution 2

After browsing many threads and articles I've found a solution. Solution tested on Windows 10 x64 on Eclipse Neon.3 Release (4.6.3) with C/C++ Development Tools 9.2.1.201704050430 and MinGW

System configuration

  1. Download MinGW. Any distro might work. I used the distro recommended on http://isocpp.org/
  2. Extract archive into C:\MinGW (actually to C:\, because archive contains folder MinGW)
  3. RMB on This PC -> Properties -> Additional system settings -> Tab Advanced-> Button Environment variables
  4. On second table System variables click New. Name variable MINGW_HOME and set path to MinGW install folder C:\MinGW and then OK
  5. Find variable Path in table and choose Edit
  6. In new window click New and type %MINGW_HOME%\bin\
  7. Confirm actions by clickig OK in opened windows
  8. You can check availability of new tools by typing in command line g++ --version You should see something like

g++ (GCC) 6.3.0 Copyright (C) 2016 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Eclipse CDT configuration

  1. Install Eclipse with CDT or just add CDT to existing Eclipse installation
  2. Go to the folder with installed MinGW (C:\MinGW\bin\). Make a copy of file gcc.exe (DO NOT RENAME original file!)
  3. Rename copied filed to mingw32-gcc.exe (You should have both files gcc.exe and mingw32-gcc.exe in \MinGW\bin\)
  4. Open Eclipse and select C\C++ perspective
  5. Go to Window -> Preferences -> C\C++ -> Build -> Environment
  6. Click Add and type PATH as name and click on Variables and select Path. Confirm with Ok.
  7. Select new variable PATH by clicking Select and then Ok.
  8. Restart Eclipse

Now you should be able to compile Hello World program. Just select New -> C++ Project. Here you should see available MinGW as Toolchain

Solution 3

Here is another good resource for installing MinGW on Eclipse: http://chrismwright.wordpress.com/2012/10/13/installing-eclipse-for-cc-and-mingw/

Pretty much a step-by-step installation including Hello World example at the end...

Share:
96,725
Jonas
Author by

Jonas

Passionated Software Developer interested in Distributed Systems

Updated on July 09, 2022

Comments

  • Jonas
    Jonas almost 2 years

    I would like to do some C++ development on Windows using Eclipse and the CDT plugin. I use Eclipse Helios SR1 and have installed the CDT plugin. I have also installed MinGW and now I wrote a simple "Hello World" in Eclipse.

    hello.cpp

    #include <iostream>
    using namespace std;
    int main()
    {
        cout << "Hello World" << endl;
        return 0;
    }
    

    In Eclipse using the CDT plugin and the MinGW compiler. How can I compile my program? And how can I test run the program from within Eclipse?