Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » console problem with printf(how to get printf work on eclipse)
console problem with printf [message #489392] Fri, 02 October 2009 19:01 Go to next message
No real name is currently offline No real nameFriend
Messages: 6
Registered: October 2009
Junior Member
Hi, i've a problem with eclipse's console... when i print something to the screen, with printf(); the screen outputs nothing until the program exits.
I fixed this with fflush(stdout); but i don't think it's the right way to do it.
Any other way?
Re: console problem with printf [message #489879 is a reply to message #489392] Tue, 06 October 2009 11:41 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
Quote:
Hi, i've a problem with eclipse's console... when i print something to the screen, with printf(); the screen outputs nothing until the program exits.
I fixed this with fflush(stdout); but i don't think it's the right way to do it.
Any other way?

No.


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: console problem with printf [message #490825 is a reply to message #489392] Sun, 11 October 2009 15:32 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 6
Registered: October 2009
Junior Member
perfect... if i don't use fflush i will read nothing, if i use it i cannot run the debug because crashes at fflush(stdout);
Re: console problem with printf [message #490869 is a reply to message #490825] Mon, 12 October 2009 06:08 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
Quote:
if i use it i cannot run the debug because crashes at fflush(stdout);

That should not happen. Does your app crash or Eclipse?


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: console problem with printf [message #491263 is a reply to message #489392] Tue, 13 October 2009 20:47 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 6
Registered: October 2009
Junior Member
the app, this is the code:
#include <stdio.h>
#include <stdlib.h>

int main(void) {
	printf("!!!Hello World!!!");
	fflush(stdout);
	return EXIT_SUCCESS;
}

and this is the error message while debugging step-to-step (after the printf, at the fflush):
!!!Hello World!!!540*stopped,reason="end-stepping-range",thread-id= "1",frame={addr="0x00401336",func="main",args=[],file="../src/test.c ",line="7"}
Re: console problem with printf [message #491312 is a reply to message #491263] Wed, 14 October 2009 06:32 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
S.raffaele.mad.scientist. wrote on Tue, 13 October 2009 16:47
the app, this is the code:
#include <stdio.h>
#include <stdlib.h>

int main(void) {
	printf("!!!Hello World!!!");
	fflush(stdout);
	return EXIT_SUCCESS;
}

and this is the error message while debugging step-to-step (after the printf, at the fflush):
!!!Hello World!!!540*stopped,reason="end-stepping-range",thread-id= "1",frame={addr="0x00401336",func="main",args=[],file="../src/test.c ",line="7"}


What platform, compiler and debugger are you using? I built and debugged your example on Linux and did not encounter any problems.

Axel


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: console problem with printf [message #491452 is a reply to message #491312] Wed, 14 October 2009 15:58 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 6
Registered: October 2009
Junior Member
i'm running windows vista x32, MinGW (gcc) as compiler with GDB (from MinGW package)

Edit, check this out:
Quote:
C:\Users\x>gcc -v
Reading specs from C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/specs
Configured with: ../gcc-3.4.5-20060117-3/configure --with-gcc --with-gnu-ld --wi
th-gnu-as --host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --dis
able-nls --enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry --d
isable-shared --enable-sjlj-exceptions --enable-libgcj --disable-java-awt --with
out-x --enable-java-gc=boehm --disable-libgcj-debug --enable-interpreter --enabl
e-hash-synchronization --enable-libstdcxx-debug
Thread model: win32
gcc version 3.4.5 (mingw-vista special r3)

C:\Users\x>gdb -v
GNU gdb 5.2.1
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i686-pc-mingw32".

[Updated on: Wed, 14 October 2009 19:18]

Report message to a moderator

Re: console problem with printf [message #491574 is a reply to message #491452] Thu, 15 October 2009 07:13 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
Quote:
GNU gdb 5.2.1

I suppose your debug problem arises from this old gdb version. There had been several bugfixes in gdb due to problems in the communication with Eclipse (or other frontends). You should try tuo update gdb (and gcc as well as, 3.4.5 is quite outdated). Either try the test releases from the official MinGW homepage or download gcc/gdb from here http://www.tdragon.net/recentgcc/. They provide up-to-date packages.



Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: console problem with printf [message #491746 is a reply to message #491574] Thu, 15 October 2009 16:08 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 6
Registered: October 2009
Junior Member
Ok, i will try what you suggested, btw MInGW stable version runs those versions of gcc, gdb. Thank you for the link you posted
EDIT: didn't work... Sad
Quote:
C:\>gcc -v
Using built-in specs.
Target: mingw32
Configured with: ../../gcc-4.4.1/configure --prefix=/mingw --build=mingw32 --ena
ble-languages=c,ada,c++,fortran,objc,obj-c++ --disable-nls --disable-win32-regis
try --enable-libgomp --enable-cxx-flags='-fno-function-sections -fno-data-sectio
ns' --disable-werror --enable-threads --disable-symvers --enable-version-specifi
c-runtime-libs --enable-fully-dynamic-string --with-pkgversion='TDM-2 mingw32' -
-enable-sjlj-exceptions --with-bugurl=http://www.tdragon.net/recentgcc/bugs.php
Thread model: win32
gcc version 4.4.1 (TDM-2 mingw32)

C:\>gdb -v
GNU gdb 6.8
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-mingw32".

[Updated on: Thu, 15 October 2009 16:28]

Report message to a moderator

Re: console problem with printf [message #491833 is a reply to message #491746] Fri, 16 October 2009 06:23 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
Quote:
and this is the error message while debugging step-to-step (after the printf, at the fflush):
!!!Hello World!!!540*stopped,reason="end-stepping-range",thread-id= "1",frame={addr="0x00401336",func="main",args=[],file="../src/test.c ",line="7"}

OK, I could reproduce it. The message part after "Hello World" comes from the debugger. You get it if you set "Verbose console mode" in the debug launch configuration (this is not the default). However, the message does not indicate an error! It just means that the debugger stopped (or better suspended) the application because stepping is used (just google the term "stopped,reason=end-stepping-range" and you will find some info about it). You will get this message for every single step.
The only weird behavior (or bug?) I see, is that you get the gdb message in the console window of you application. The gdb messages should all go to a separate console window.


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: console problem with printf [message #492283 is a reply to message #491833] Mon, 19 October 2009 18:59 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 6
Registered: October 2009
Junior Member
"verbose mode" it's not enabled in my own configuration.
Re: console problem with printf [message #497012 is a reply to message #489879] Thu, 12 November 2009 09:21 Go to previous messageGo to next message
ADLR  is currently offline ADLR Friend
Messages: 2
Registered: November 2009
Junior Member
I do have the same issue, can I somehow use another Console as output on my Windows machine? Crying or Very Sad
Re: console problem with printf [message #525029 is a reply to message #497012] Mon, 05 April 2010 13:22 Go to previous messageGo to next message
JAN LIND is currently offline JAN LINDFriend
Messages: 1
Registered: April 2010
Junior Member
I have the same problem and it must come from the Eclipse environment. When running gdb from a command line, everything works fine, but when I run exactly the same version of gdb from Eclipse it hangs in fflush for stdout or fgets for stdin. I think it is obvious that Eclipse has problems with stdio in a Windows environment. My environment is

Windows XP SP3
minGW 5.1.6
gdb 6.6 (also tried 6.8 and 7.0, but the same problem)

[Updated on: Mon, 05 April 2010 19:29]

Report message to a moderator

Re: console problem with printf [message #528047 is a reply to message #525029] Mon, 19 April 2010 06:26 Go to previous message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
The Eclipse console has buffering problems on Windows. Basically, it doesn't flush the streams when a newline is received. (Unlike a normal windows console window)
Either, you have to add fflush calls when needed or add the following lines in the start of the main function:
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Previous Topic:"make target build" key binding not working
Next Topic:Eclipse hangs on opening an CDT project
Goto Forum:
  


Current Time: Mon Jun 01 00:10:17 GMT 2015

Powered by FUDForum. Page generated in 0.01913 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software