14

I'm using Windows 7 64bit.

I installed eclipse version 3.6.2, cdt, and MinGW. I have a C++ console program in Eclipse as follows:

#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    setbuf(stdout, NULL);

    for (int i = 0; i < 10000000; i++) {
        cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    }
    int val;
    cin >> val;

    return 0;
}

If I run this console program, it should display Hello world to Console View in Eclipse, but nothing displays.

If I go to the debug folder and run the exe, it does print to the console.

If I make some syntax mistake, then the Eclipse Console View will show something, such as:

**** Internal Builder is used for build ****
g++ -O0 -g3 -Wall -c -fmessage-length=0 -osrc\hh.o ..\src\hh.cpp
..\src\hh.cpp: In function 'int main()':
..\src\hh.cpp:17:3: error: expected ';' before 'return'
Build error occurred, build is stopped
Time consumed: 255 ms.   

Why is nothing showing in the Eclipse console view and how can I make my C++ console program display output?

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
Gqqnbig
  • 5,845
  • 10
  • 45
  • 86

13 Answers13

22

I found a workaround from this site: http://www.eclipse.org/forums/index.php?=42e862594001fa4469bbc834885d545f&t=msg&th=197552

At that link, look at the reply from "No real Name".

In case the link goes down, here is the content:

Environment: jdk1.6u18 64bit + Eclipse Helios 64bit + win7 64bit

No console output at "Run", but output correctly at "Debug".

The following method worked for me:

1.  Goto Project->Properties->Run/Debug Settings, choose the .exe file 
and press "Edit"

2.  In the "Environment" tag, press "New", set it as: 
    "Name:PATH"
    "Value:C:\MinGW\bin"

In fact, I have already set "C:\MinGW\bin" in windows PATH environment 
variable, but it seemed to not work.
Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
Vikyboss
  • 940
  • 2
  • 11
  • 23
  • 1
    This worked for me (except in my case I added the Cygwin path). Do you have any idea why this is necessary? If I go into the C++ Build settings, the path is already there, so why does it need to be added twice? – gsgx Feb 15 '12 at 22:58
5

The problem is that your program uses dll libraries from MinGW - try to start the exe file manually, it will report some error about missing dlls.

Solution can be, that you copy required dlls to .exe file in your project directory (and Release or Debug subdirectory, depends on what .exe are you executing with Run command).

Or, in menu Run -> Run Configuration select the configuration which you use for that .exe file (or create a new C/C++ Application configuration) and select Environment tab in the right panel. There add new variable named PATH with value c:\MinGW\bin (this is default path to mingw\bin directory, use a path valid for your instalation if it's somewhere else)
Edit: Now I'm looking at post by Vikyboss and it's in fact the same - setting the PATH variable in Run configuration. Setting PATH variable in Preferences > C/C++ (Expand it) > Environment as described by Sydraps didn't work for me.

But I think that static linking that libraries may be the best solution for you. In menu Project -> Properties select C/C++ Build -> Settings. In the right panel select Configuration which you want to change (you may select All). In the tab Tool Settings select MinGW C++ Linker -> Miscellaneous and in the right panel in the Linker flags type -static. Now the .exe will be bloated by the size of the libraries (in my case approx. +900kB for Hello world example, requiring 2 dlls), but it will be independent at any libraries.

I hope this will be helpful for anyone trying to start with Eclipse C/C++ and wondering why there's no Hello world in console. Ales Chlubny

Ales Chlubny
  • 51
  • 1
  • 2
  • Thanks. This was driving me insane, and since I don't generally use Windows I was having a hard time finding the problem. – MegFord May 03 '13 at 04:31
3

I fixed the problem on my windows 7 x64 PC. In the Eclipse window go to Preferences > C/C++ (Expand it) > Environment > Add:

"Name:PATH"
    "Value:C:\MinGW\bin"

If this does not fix it. Try adding the above to the system environment variables on your PC in Computer > Advanced System settings

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
Sydraps
  • 31
  • 1
2

I find the reason, just because I'm using 64bit eclipse!

I turn to 32 bit eclipse, the same code works fine.

Gqqnbig
  • 5,845
  • 10
  • 45
  • 86
2

My problem with displaying hello world(64 bit Windows7) in console was solved when I ran eclipse as administrator.

I added the C:\MinGW\bin to environment variable path and then started eclipse as administrator

Glenn Slaven
  • 33,720
  • 26
  • 113
  • 165
Jipson
  • 21
  • 1
1

If you are using MinGW compiler,

Add -static-libgcc -static-libstdc++ as Linker flags for your new project. This text should be added to the Linker flags field, which can be found by right-clicking on the new Project in the Project Explorer and clicking on Properties. Under the Project Properties, expand the C/C++ Build menu and click on Settings. Under the Tool Settings tab, expand the MinGW C++ Linker menu and click on Miscellaneous. Add the text to the Linker flags field, then click the Apply button.

http://orfe.princeton.edu/help/article-296

Kevin Panko
  • 8,356
  • 19
  • 50
  • 61
1

I created a Hello World C++ Project (MinGW GCC) app from the Eclipse wizard, cut and pasted your code and it compiled fine. Then prior to running I reduced your loop to 10 and it ran fine.

You don't say how you created your project but it would appear likely your missing some include directive or library path. Also I don't see the need to include or setbuf(stdout, NULL). I also find it helpful when troubleshooting to NOT bring an entire namespace into scope. Rather do this: using std::cout; using std::cin;

Finally, flushing the buffer each time with << endl; seems like overkill, adding a simple \n to the end of the string would be more efficient. (I did all this on Win 7 64 bit - but I was using a 32 bit version of Eclipse Galileo)

Tod
  • 8,192
  • 5
  • 52
  • 93
  • '<< endl' doesn't flush the buffer, it had an end line. – ALOToverflow May 12 '11 at 19:24
  • I guess that's true since the stream is now unbuffered and endl adds a new line and flushes **buffered** streams. Still for trying to get something simple to work, I don't see the point in adding what seems to be unnecessary complexity. – Tod May 12 '11 at 23:51
0

Just added the C:\MinGW\bin to environment variable 'Path' in Windows 7 64-bit. Now Console outputs messages

agelbess
  • 4,249
  • 3
  • 20
  • 21
0

I encountered a similar problem.

Environment:

jdk1.6u18 64bit + Eclipse Helios 64bit + win7 64bit

No console output at "Run", but output correctly at "Debug".

The following method worked for me:

  1. Go to Project > Properties > Run/Debug Settings

    Choose the .exe file and press "Edit"

  2. In the "Environment" tag, press "New", set it as:

"Name:PATH"

"Value:C:\MinGW\bin"

In fact, I have already set "C:\MinGW\bin" as the Windows PATH environment variable, but it seemed to not work.

Community
  • 1
  • 1
0

Works for me by going Administator on Eclipse Kepler 64bit.

nbout
  • 1,159
  • 8
  • 12
0

In case someone is interested, I found how to fix it forever on Windows XP (may work in other windows version though) without you having to specify the variables of each executable and such:

Start Menu > RightClick on MyComputer > Properties > Advanced Options > Environment Variables

There, in the "User variables" field,

  • If there's an environment variable called PATH, select Modify and add this information in the end of the Value field, separated by semicolon:

C:\MinGW\bin

Example: C:\SomeDirectory; C:\Another; C:\MinGW\bin

  • If the environment variable PATH does not exist, add a new one with this information:

Name: PATH

Value: C:\MinGW\bin

Accept all and you should get console output :)

Community
  • 1
  • 1
pablo
  • 1
  • 1
0

For me installing the 32 bit versions of Eclipse (Indigo 3.7) and the 32 bit Java JDK/JRE did not work. I use the much quicker solution from the Eclipse CDT/User/FAQ:

Quote from Eclipse CDT/User/FAQ - Eclipse console does not show output on Windows:

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

setvbuf(stdout, NULL, _IONBF, 0); 
setvbuf(stderr, NULL, _IONBF, 0);
trenki
  • 7,133
  • 7
  • 49
  • 61
0

I had an issue with my eclipse-cdt, new C++ project > hello world (cygwin gcc), right click on exe file, run as and nothing was showing on console. It was the same with c project.

I saw that my eclipse version was already a 32bits one.

I figured this out and here is (the) my solution:

There are several compilation profiles in eclipse cdt: release and debug. The default profile in eclipse cdt is debug. So, launching exe using "run as" does not work, you should launch it using "debug as". In my case, I was using a really recent cygwin installation with gcc installed, but with gdb not yet installed. I had to install gdb package in cygwin using cygwin-setup. I reran the exe using "debug as" and it worked.

I guess using release profile instead of default debug profile, rebuilding also works, and I guess that it's the same with mingw environment.

yohann.martineau
  • 1,523
  • 1
  • 17
  • 24