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

4

18

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?

Postmistress answered 20/10, 2010 at 14:26 Comment(1)
Here is another good resource for installing MinGW on Eclipse: chrismwright.wordpress.com/2012/10/13/… Pretty much a step-by-step installation including Hello World example at the end...Timmerman
H
12

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

Helical answered 20/10, 2010 at 14:46 Comment(1)
Thanks, I hadn't set the environment variables for MinGW and MSYS.Postmistress
R
6

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

Remitter answered 30/5, 2017 at 10:56 Comment(0)
T
0

Just add MinGW to System Path(System configuration part in AndriiL's post) is enough. The variable named PATH with ${PATH} as value will be added automatically in Window -> Preferences -> C\C++ -> Build -> Environment and you can see MinGW GCC as a toolchain option in project wizard. If no PATH variable presented, Eclipse CDT may not load the recent System Path changes in the OS(Click Select... and choose Path variable, the value may not contain MinGW path), just Exit Eclipse and open it again.

Trimetric answered 11/2, 2019 at 5:44 Comment(0)
A
0

Chocolatey is one package manager that allows mingw install with a single command using Windows Powershell.

choco install mingw --version=8.1.0

After the installation is done, add the below toolchain path to Eclipse->Window->Preferences-> Core Build ToolChains -> User Defined ToolChains.

C:\ProgramData\chocolatey\lib\mingw\tools\install\mingw64\bin\gcc.exe

Restart eclipse. The MinGW toolchain should be available for use now in Eclipse.

Ambidexterity answered 6/2, 2022 at 5:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.