C++ – Eclipse CDT Console output not showing up in debug with path and not showing up in run without path

cconsoleeclipseeclipse-cdtgcc

I'm trying to get Eclipse CDT (64 bit eclipse) working on Windows 7 with GCC. When I first got GDB working (that was a challenge in itself), running the program in debug mode was the only way I got output. Running it normally didn't give any console output. After hours of googling, I figured out that if I added C:/cygwin/bin to my environment path in eclipse, I could get output when running the program normally. Then I ran it in debug mode and there was no output. I tested this a couple of times to make sure it was the addition of the path causing the problem. This is the program I was running,

#include <iostream>

using namespace std;

int main() {
    cout << "Hello World!" << endl;
    return 0;
}

So how can I get both normal and debug modes working, and why did I have to include that path in the first place (it's already in my cygwin path and why does CDT need it?) ? Also, why is it that if I add a path to my Run configurations it will also be added to my Debug configurations?

Best Answer

From wiki eclipse: In Eclipse CDT on Windows, standard output of the program being run or debugged is fully buffered, because it is not connected to a Windows console, but to a pipe. See bug 173732 for more details. Either add flush calls after every printf or add the following lines at the start of the main function:

setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);