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

Viewed 98556

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?

4 Answers

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.

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.

Related