'How to compile and run C++ with MinGW using Eclipse and CDT?
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?
Solution 1:[1]
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
- Download MinGW. Any distro might work. I used the distro recommended on http://isocpp.org/
- Extract archive into
C:\MinGW(actually toC:\, because archive contains folderMinGW) - RMB on
This PC->Properties->Additional system settings-> TabAdvanced-> ButtonEnvironment variables - On second table
System variablesclickNew. Name variableMINGW_HOMEand set path to MinGW install folderC:\MinGWand thenOK - Find variable
Pathin table and chooseEdit - In new window click
Newand type%MINGW_HOME%\bin\ - Confirm actions by clickig
OKin opened windows - You can check availability of new tools by typing in command line
g++ --versionYou 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
- Install Eclipse with CDT or just add CDT to existing Eclipse installation
- Go to the folder with installed MinGW (
C:\MinGW\bin\). Make a copy of filegcc.exe(DO NOT RENAME original file!) - Rename copied filed to
mingw32-gcc.exe(You should have both filesgcc.exeandmingw32-gcc.exein\MinGW\bin\) - Open Eclipse and select
C\C++perspective - Go to
Window->Preferences->C\C++->Build->Environment - Click
Addand typePATHas name and click onVariablesand selectPath. Confirm withOk. - Select new variable
PATHby clickingSelectand thenOk. - 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 2:[2]
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...
Solution 3:[3]
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.
Solution 4:[4]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | AndriiL |
| Solution 2 | JFXNerd |
| Solution 3 | Harshith Rai |
| Solution 4 |
