Beruflich Dokumente
Kultur Dokumente
2.1 Writing Toy Programs (without Creating a P 2.2 Writing Programs (under Project) 2.3 Writing Many Toy Programs under ONE Pr
CodeBlocks is an open-source, cross-platform (Windows, Linux, Mac), and free C/C++ IDE. CodeBlock supports many compilers, such as GCC (MingGW and GNU GCC) 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.
5/13/12
in
particular,
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). The drawback is you cannot debug program without creating a project.
5/13/12
4. To build the program, select "Build" menu Build. 5. To run the program, select "Build" menu Run. 6. To create more source file or header file under the project: a. File New File... Select C/C++ source or C/C++ header. b. C++ Next. c. In "Filename with full path" Click the "Navigate" (...) button to navigate to the project directory and enter the new file name. Check both the "Debug" and "Release" boxes (or "All") Finish.
5/13/12
5. Build and run the program. 6. Check your project directory, which shall show that both the m a i n . c p pand H e l l o . c p pare present. 7. Suppose that you wish to run "m a i n . c p p " again: First remove "H e l l o . c p p " from the project. Right-click on the project Add File... Choose "m a i n . c p p " Open Check both the "Debug" and "Release" box OK. You can now build and run the "m a i n . c p p ". In brief, use the "Add File" and "Remove File" to place your desired toy program file (with the m a i n ( ) function) under the active project. You can then "Build" the project and "Run" your toy program.
www3.ntu.edu.sg/home/ehchua/programming/howto/CodeBlocks_HowTo.html
4/7
5/13/12
5/13/12
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".
5/13/12
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?]
Feedback, comments, corrections, and errata can be sent to Chua Hock-Chuan (ehchua@ntu.edu.sg) | HOME
www3.ntu.edu.sg/home/ehchua/programming/howto/CodeBlocks_HowTo.html
7/7