Is there a console-like window where I can print text in devcpp ide? You know something like the debug window in visual basic. Most importantly would I want to monitor the value of a variable without halting the program. I usually use the MessageBox function to print values of variables...Is there any other approach to view the values yet let my program continue execution.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
No I don't want to create an explicit console window or anything of that sort. I want to know if there is an in-built IDE feature that fills my description.
If you have a visual basic experience we include lines such as
Debug.Print "Value of variable = " & var1
OR
If my program's execution invoked a function I'd include a line like :
Debug.Print "Inside func myFunc()"
inside my function (at the beginning) so that I know that my program is running myFunc().
Those "debug.print" things get outputted to a window called the immediate window which is an integral part of the IDE.
The compile log is one of tabs you see in the compiler output in devcpp ide. So I was wondering if you could output text there...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2007-08-03
No there is not a feature that does that, however Wayne's suggestion will achieve much the same result for GUI development. A GUI program can also have a console that responds to standard console I/O (printf, scanf, cout, cin etc.)
If you create a macro thus:
if defined __DEBUG __
include <cstdio>
define DEBUGPRINTF( format, ... ) fprintf( stderr, "\n%s::%s(%d):" format, FILE, FUNCTION, LINE, VA_ARGS )
else
define DEBUGPRINTF( format, args... ) // do nothing
endif
You can then use DEBUGPRINTF() just like printf() and it will only generate output in debug builds. You can use this in console apps as is. To use it in a GUI app, you have to enable the console window as follows:
In your Win32 GUI project, go to Project->Project options->General, In the "Type" selection, select Win32 Console, this removes the -mwindows option which is what suppresses the console window - you will still get a GUI window. This is the same as setting "Do not create a console window" to "No" in the linker options, but that option disappears when the type is set to Win32 GUI.
The macro automatically inserts the filename, function name and line number, so:
DEBUGPRINTF( "x=%d", x ) ;
might output:
main.cpp::main(10):x=10
for example.
Of course you could always use the debugger - the debugger actually supports the functionality you are asking for, but because the Dev-C++ integration of GDB is flawed, it probably not going to work well. The more-or-less exact same question was asked here: https://sourceforge.net/forum/message.php?msg_id=3415237 maybe you'll get something from that. You could try using the Insight debugger instead (available at www.mingw.org) - it too is based on GDB but is less flaky, or you could if you are hard use GDB directly.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Tried adding the macro code and carried out instructions as you told, but I am getting a linker error and hence not able to execute the code. I have put the lines of code in the beginning.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thats a cool idea. But won't the console disappear if my programs aborts due to some unhandled exception? I am looking for something that persists even after the execution.
Once again thanx for the idea.
Does devcpp IDE have some sort of an object model?
--deostroll
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2007-08-03
OK, here is another more sophisticated option:
Create a variadic function that works like printf, but sends the text via TCP/IP to IP address 127.0.0.1 (localhost). Then you create a separate program that listens on the port that your function is sending on and displays and text it receives. You then use this function in a macro similar to the one above. Of course you could use a remote machine just by using a different IP address.
Of course this function is likely to need some additional support functions to open the connection etc, this can be wrapped in conditional compilation so it is only included when needed.
Because the debug is output by a separate process, it won't die when your program does.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2007-08-03
... oh and a far simpler idea that has just ocurred, use fprintf instead of printf so the debug text ends up in a file so is persistent. You could even use printf and fprintf within one debug macro so it goes to both destinations.
Another idea: if you have a machine with a couple of serial ports (or one port and a second PC with another) , you can use fprintf opened on one COM port, and open HyperTerminal or TeraTerm or similar on the other port - connecting teh two ports with a null modem cable.
In fact using the serial connection, you could leave the debug code using printf and simply redirect stdout when you run your program from the command line thus:
myprog.exe > com1:
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Please do NOT excerpt the errors out of the log. Post your compile log,
starting from the beginning. The compile lof is on the tab labeled
"Compile Log", and the right mouse button brings up the copy menu.
This is critical in this case, as your error is a linker error, and
you threw away the information on what you linked when you excerpted
the error.
I want to see for example, if you have added the link command that looks
something like:
-lgdi32
Note that if you want to avoid having me lecture you about the log,
this forum does have a search function, had you searched on the
distinctive error
"GetStockObject"
You would have foind a number of previous questions, and answers
on what to link. (I know, I have answered a bunch)
I tell you this, not to annoy you, but to give you the tools to
fix things without listening to an old fart babble.
Wayne
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Mighty thanks drwayne. Now even my itoa() works!!! :)
Btw I did not know what search string to use which was why I popped my question directly to this place. I apologize if this annoyed you.
Thank you once again.
--deostroll
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I used to semi-joke that the most useful skill I learned in school was the ability
to use an index.
These days, being able to use a search engine is an extremely valuable skill.
When you have a distinctive term in an error, like the one I pointed out, go
for it. If it doesn't work, try another. I seldom google on the right thing
to start with.
Many times, you learn something from just looking around in this manner.
I have learned about libraries I never heard of before, that were very useful
to me just by looking around and playing. This is time you are investing
in yourself.
Wayne
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I can't use the function itoa() either...
--deostroll
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2007-08-08
For undefined references the solution is always the same. Find out what library it is in, and link it.
Finding the library can be done by checking the documentation (in this case it is in the MSDN library) or even by doing a plain text search of the library folder - they are binaries, but the symbols are readable ASCII. Of course you may have to figure out what library defines a symbol and what simply references it, but usually by then it is obvious or a very limited choice. You can use the nm tool to dump a libraries symbols if necessary.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Is there a console-like window where I can print text in devcpp ide? You know something like the debug window in visual basic. Most importantly would I want to monitor the value of a variable without halting the program. I usually use the MessageBox function to print values of variables...Is there any other approach to view the values yet let my program continue execution.
I take it you are compiling windows programs, but you would like to have a console within that? Or am I misreading your question?
Wayne
No I don't want to create an explicit console window or anything of that sort. I want to know if there is an in-built IDE feature that fills my description.
If you have a visual basic experience we include lines such as
Debug.Print "Value of variable = " & var1
OR
If my program's execution invoked a function I'd include a line like :
Debug.Print "Inside func myFunc()"
inside my function (at the beginning) so that I know that my program is running myFunc().
Those "debug.print" things get outputted to a window called the immediate window which is an integral part of the IDE.
The compile log is one of tabs you see in the compiler output in devcpp ide. So I was wondering if you could output text there...
No there is not a feature that does that, however Wayne's suggestion will achieve much the same result for GUI development. A GUI program can also have a console that responds to standard console I/O (printf, scanf, cout, cin etc.)
If you create a macro thus:
if defined __DEBUG __
include <cstdio>
define DEBUGPRINTF( format, ... ) fprintf( stderr, "\n%s::%s(%d):" format, FILE, FUNCTION, LINE, VA_ARGS )
else
define DEBUGPRINTF( format, args... ) // do nothing
endif
You can then use DEBUGPRINTF() just like printf() and it will only generate output in debug builds. You can use this in console apps as is. To use it in a GUI app, you have to enable the console window as follows:
In your Win32 GUI project, go to Project->Project options->General, In the "Type" selection, select Win32 Console, this removes the -mwindows option which is what suppresses the console window - you will still get a GUI window. This is the same as setting "Do not create a console window" to "No" in the linker options, but that option disappears when the type is set to Win32 GUI.
The macro automatically inserts the filename, function name and line number, so:
DEBUGPRINTF( "x=%d", x ) ;
might output:
main.cpp::main(10):x=10
for example.
Of course you could always use the debugger - the debugger actually supports the functionality you are asking for, but because the Dev-C++ integration of GDB is flawed, it probably not going to work well. The more-or-less exact same question was asked here: https://sourceforge.net/forum/message.php?msg_id=3415237 maybe you'll get something from that. You could try using the Insight debugger instead (available at www.mingw.org) - it too is based on GDB but is less flaky, or you could if you are hard use GDB directly.
Clifford
Tried adding the macro code and carried out instructions as you told, but I am getting a linker error and hence not able to execute the code. I have put the lines of code in the beginning.
Thats a cool idea. But won't the console disappear if my programs aborts due to some unhandled exception? I am looking for something that persists even after the execution.
Once again thanx for the idea.
Does devcpp IDE have some sort of an object model?
--deostroll
OK, here is another more sophisticated option:
Create a variadic function that works like printf, but sends the text via TCP/IP to IP address 127.0.0.1 (localhost). Then you create a separate program that listens on the port that your function is sending on and displays and text it receives. You then use this function in a macro similar to the one above. Of course you could use a remote machine just by using a different IP address.
Of course this function is likely to need some additional support functions to open the connection etc, this can be wrapped in conditional compilation so it is only included when needed.
Because the debug is output by a separate process, it won't die when your program does.
Clifford
... oh and a far simpler idea that has just ocurred, use fprintf instead of printf so the debug text ends up in a file so is persistent. You could even use printf and fprintf within one debug macro so it goes to both destinations.
Another idea: if you have a machine with a couple of serial ports (or one port and a second PC with another) , you can use fprintf opened on one COM port, and open HyperTerminal or TeraTerm or similar on the other port - connecting teh two ports with a null modem cable.
In fact using the serial connection, you could leave the debug code using printf and simply redirect stdout when you run your program from the command line thus:
myprog.exe > com1:
Clifford
I've converted my project to a console application but I got the following error:
D:\Dev-Cpp\Graphics Console\main.o(.text+0x433) - In function
Z5printP6HWND(char *)': - [Linker error] undefined reference to
GetStockObject@4'- [Linker error] undefined reference to `SelectObject@8'
D:\Dev-Cpp\Graphics Console\main.o(.text+0x433) - ld returned 1 exit status
D:\Dev-Cpp\Graphics Console\Makefile.win - [Build Error] [gc.exe] Error 1
I am using gdi functions in the applications though.
Please do NOT excerpt the errors out of the log. Post your compile log,
starting from the beginning. The compile lof is on the tab labeled
"Compile Log", and the right mouse button brings up the copy menu.
This is critical in this case, as your error is a linker error, and
you threw away the information on what you linked when you excerpted
the error.
I want to see for example, if you have added the link command that looks
something like:
-lgdi32
Note that if you want to avoid having me lecture you about the log,
this forum does have a search function, had you searched on the
distinctive error
"GetStockObject"
You would have foind a number of previous questions, and answers
on what to link. (I know, I have answered a bunch)
I tell you this, not to annoy you, but to give you the tools to
fix things without listening to an old fart babble.
Wayne
Mighty thanks drwayne. Now even my itoa() works!!! :)
Btw I did not know what search string to use which was why I popped my question directly to this place. I apologize if this annoyed you.
Thank you once again.
--deostroll
I used to semi-joke that the most useful skill I learned in school was the ability
to use an index.
These days, being able to use a search engine is an extremely valuable skill.
When you have a distinctive term in an error, like the one I pointed out, go
for it. If it doesn't work, try another. I seldom google on the right thing
to start with.
Many times, you learn something from just looking around in this manner.
I have learned about libraries I never heard of before, that were very useful
to me just by looking around and playing. This is time you are investing
in yourself.
Wayne
I can't use the function itoa() either...
--deostroll
For undefined references the solution is always the same. Find out what library it is in, and link it.
Finding the library can be done by checking the documentation (in this case it is in the MSDN library) or even by doing a plain text search of the library folder - they are binaries, but the symbols are readable ASCII. Of course you may have to figure out what library defines a symbol and what simply references it, but usually by then it is obvious or a very limited choice. You can use the nm tool to dump a libraries symbols if necessary.
Clifford