DEV-C is a fully-featured integrated development environment (IDE) for creating, debugging and creating applications written in a popular C programming language. Even though tools for the development of C software have undergone countless upgrades over the years, a large number of developers located all around the world have expressed a wish to continue using DEV-C. If your program is reading input from standard input and you forgot to provide input via stdin. Your program contains infinite loop, which may never break. Your program contains infinite recursive function calls. May be your program.
How to write and compile C++ programs
In order to run a program and see it doing wonderful things, you should first write the program. The program can be written in any text editor, such as vi and emacs in Unix environment and using command prompt in DOS. There are also several Integrated Development Environment (IDE) packages available which provide a complete programming environment for C++ in which you can write, compile, run, and debug your program.
C++ programs are saved with extensions .C, .cc, .cpp, .cxx depending on the platform you are working upon.
Once you have saved a program, next stage is compiling it using a compiler which converts your C++ program into the object code which the computer can understand.
Compile using g++ compiler
If you are using UNIX environment and using g++ compiler, then compiling your C++ program is simple. After you have saved the program file, simply type the command
g++ program.cc –o program
where program is the name of the program. For example the name of our first program is first, then save it using extension “first.cc”. To compile, type
g++ first.cc –o first
To run the program, type first or ./first at the command prompt and your program will run.
Compile using DevC++ compiler
If you work on Windows and use DevC++, then editing and compiling is as easy as click of a button. DevC++ is an IDE which allows you to edit, compile, run and debug your program in the IDE itself. If you want to install DevC++ then install it from DEV C++ website.
Once you have installed and configured the software, Write and save your program using DevC++ itself. Create a new program by clicking on New à Project.
Choose Empty Project from New Project dialog and choose a name for the program, in our case first and click Ok.
Write the code of the program and save it.
Click on Compile button (third row, first button) to compile your source code. If there are any errors in your program, then a window at the bottom will specify the warnings.
After program is compiled, click on Run button (next to compile).
However, DevC++ has a problem. As soon as you Run the program, output window opens momentarily and then it closes. So to come around this solution, set a breakpoint at the end of main function and then click on Debug instead of running it.
When you run the program, output window will show the string.
Compile using VC++
If you use Visual C++ toolkit for C++ programming, then the procedure is same as in DevC++.
To write the source code>, Click on File à New Project. A dialog box will appear, click on A Empty Project and click Finish. Write your source code in the source code window.
After you have saved your source code, click on Build button to compile the source code.
Once the source code is compiled, click on Execute button to run the program. An output window will show the output of the program.
How To Debug C Program In Dev Code
Now we have learnt how to edit, compile and run programs using compilers and IDE, its time to learn about more features of C++ language to get some real action. Next tutorial, Data Types and Variables tells about data types in C++, keywords and variables.
How To Debug C Program In Dev Cprogram In Dev C++
Go to the previous lesson or proceed to the next lesson Table of contents
How do I debug using Dev-C++?
First, make sure you are using a project.
How To Debug In Linux
How To Debug Program In Dev C++
Then go to Project Options - Compiler - Linker and set Generate debugging information to 'yes', and make sure you are not using any optimization options (they're not good for debug mode). Also check the Parameters tab, make sure you don't have any optimization options (like -O2 or -O3, but -O0 is ok because it means no optimization) or strip option (-s). After that, do a full rebuild (Ctrl-F11), then set breakpoint(s) where you want the debugger to stop (otherwise it will just run the program). To set a breakpoint on a line, just click on the gutter (the gray band on the left), or press Ctrl-F5.
Now you are ready to launch the debugger, by pressing F8 or clicking the debug button. If everything goes well, the program will start, and then stop at the first breakpoint. Then you can step through the code, entering function calls, by pressing Shift-F7 or the 'step into' button, or stepping over the function calls, by pressing F7 or the 'next step' button. You can press Ctrl-F7 or the 'continue' button to continue execution till the next breakpoint. At any time, you can add or remove breakpoints.
How To Debug In Dev C++
When the program stopped at a breakpoint and you are stepping through the code, you can display the values of various variables in your program by putting your mouse over them, or you can display variables and expressions by pressing F4 or the 'add watch' button and typing the expression.
How To Debug A Program In Dev C++
For more information refer to the help included with Dev-C++.