How To Install CodeBlocks and Get Started With C - C++ Programming
How To Install CodeBlocks and Get Started With C - C++ Programming
2.1 Writing Toy Programs (without Creating a P 2.2 Writing Programs (under Project) 2.3 Writing Many Toy Programs under ONE Pr
3. CodeBlocks' Common Errors 4. Debugging C/C++ Program in CodeBlocks 5. Tips and Tweaks
CodeBlocks is an open-source, cross-platform (Windows, Linux, MacOS), and free C/C++ IDE. It supports many compilers, such as GNU GCC (MinGW and Cygwin) and MS Visual C++. It supports interactive debugging (via GNU GDB or MS CDB). CodeBlocks is surprisingly versatile, and in my opinion, much better than the Visual Studio suite. The mother site of CodeBlocks is www.codeblocks.org.
Step 2: Install
Run the downloaded installer. Accept the default options.
Verify the Compiler's and Debugger's Path : (For CodeBlocks 13.12 For Windows) Goto
"Settings" menu "Compiler..." In "Selected Compiler", choose "GNU GCC Compiler" Select tab "Toolchain Executables" Check the "Compiler's Installation Directory". It shall be set to the
http://www3.ntu.edu.sg/home/ehchua/programming/howto/CodeBlocks_HowTo.html 1/8
2/5/2014
"MinGW" sub-directory of the CodeBlocks installation directory, for example, suppose that CodeBlocks is installed in "c : \ P r o g r a m F i l e s \ c o d e b l o c k s ", set it to "c : \ P r o g r a m F i l e s \ c o d e b l o c k s \ M i n G W ". Similarly, check the debugger's path. Goto "Settings" menu "Debugger..." Expand "GDB/CDB debugger" Select "Default" In "Executable path", provide the full-path name of "g d b . e x e ", for example, "c : \ P r o g r a mF i l e s \ c o d e b l o c k s \ M i n G W \ b i n \ g d b . e x e ".
Save the file as "H e l l o . c p p " in your project directory (e.g., "d : \ p r o j e c t "). 3. Build (Compile and Link): Select "Build" menu Build (Ctrl-F9). 4. Run: Select "Build" menu Run (Ctrl-F10).
http://www3.ntu.edu.sg/home/ehchua/programming/howto/CodeBlocks_HowTo.html 2/8
2/5/2014
The drawback is you cannot debug program without creating a project. Read "CodeBlocks' Common Errors" if ....
2/5/2014
1. From "File" menu "Recent Projects" Choose the desired project; or 2. From "File" menu "Open..." Navigate to your project directory "P r o j e c t N a m e . c b p ", where ".cbp" stands for CodeBlocks-Project. Read "CodeBlocks' Common Errors" if .... Choose
2/5/2014
1. You downloaded the CodeBlocks with "MinGW GNU C/C++ Compiler" (e.g., "c o d e b l o c k s 1 0 . 0 5 m i n g w s e t u p . e x e "). 2. Goto "Settings" menu "Compiler..." Select tab "Toolchain Executables" Check the "Compiler's Installation Directory". It shall be set to the "MinGW" sub-directory of the CodeBlocks installation directory, e.g., "c : \ P r o g r a m F i l e s \ c o d e b l o c k s \ M i n G W " suppose that CodeBlocks is installed in "c : \ P r o g r a mF i l e s \ c o d e b l o c k s ".
Cannot Build or Run Program - Build/Run Buttons and Menu-Items are Grey and Not Selectable
A previous program is still running. You need to terminate the program by closing the output console window.
(For C Programs) System Error: " xxx .exe has stopped working"
Check your s c a n f ( )function. You probably omitted the ' & 'before the variable name.
http://www3.ntu.edu.sg/home/ehchua/programming/howto/CodeBlocks_HowTo.html
2/5/2014
1 6 1 7 1 8 1 9
2/5/2014
Click the "Next line" button on the "Debug" toolbar to single-step thru your program. At each of the step, you could examine the internal state of your program, such as the value of the variables (in the outputs "Watches" produced pane), the by your
program (in the console), etc. Single-stepping thru the program and watching the values of the variables and the outputs produced is the ultimate mean in debugging programs - because it is exactly how the computer runs your program!
Other Debugging Features Step-Into and Step-Out: To debug a function, you need to use "Step-Into" to step into the
first statement of the function. ("Step-Over" runs the function in a single step without stepping through the statements inside the function.) You could use "Step-Out" to return to the caller, anywhere within the function. Alternatively, you can set a breakpoint inside a function.
Watching a Variable: To add a variable into the "Watches" panel, goto "Debug" "Edit
Watch..." "Add" Enter the variable name You can select the format, or "watch as array".
2/5/2014
1. Re-format Source Code: Right-click on the source file Format this file (AStyle). [Source formatting feature is provided by a plugin called AStyle, which can be accessed via menu "Settings" "Editor..." "Source Formatter".] the available options. 3. Abbreviation: e.g., type "for" and press control-J to get the skeleton of for-loop. The abbreviation list can be configured in "Settings" menu "Editor..." "Abbreviations". 4. Zoom in/out on Editor Panel: Either: a. From "Edit" menu "Special Commands" "Zoom" "In", "Out", or "Reset", or b. Hold the control key and zoom in/out via the mouse scroll wheel, or c. Use keyboard shortcut: control number-pad + (zoom in), control number-pad / (zoom out). 5. Configure Editor: Right-click on the editor panel "Configure editor...". a. Source Formatter: You can choose the "Java" style. b. [TODO] more 6. [How to link to API documentation?] "Plugins" "Source Code Formatter (AStyle)". To configure the formatting styles, goto 2. Auto-Complete: type the initial letters of a keyword/identifier and press Ctrl-space to list
Feedback, comments, corrections, and errata can be sent to Chua Hock-Chuan (ehchua@ntu.edu.sg) | HOME
http://www3.ntu.edu.sg/home/ehchua/programming/howto/CodeBlocks_HowTo.html
8/8