0% found this document useful (0 votes)
15 views

InstallingCodeBlocks (1)

The document provides instructions for installing and using Code::Blocks, an Integrated Development Environment (IDE) with a C++ compiler, for programming modules in Computer Science. It outlines the installation process, how to create and save a C++ source file, and the steps to compile and run a program. Additionally, it emphasizes the importance of saving files in directories without spaces to avoid errors.

Uploaded by

ramduthlukesh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

InstallingCodeBlocks (1)

The document provides instructions for installing and using Code::Blocks, an Integrated Development Environment (IDE) with a C++ compiler, for programming modules in Computer Science. It outlines the installation process, how to create and save a C++ source file, and the steps to compile and run a program. Additionally, it emphasizes the importance of saving files in directories without spaces to avoid errors.

Uploaded by

ramduthlukesh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Code::Blocks

A number of programming modules in Computer Science (namely COS1511/INP1501,


COS1512 and COS2611) use the same prescribed software; in particular, an Integrated
Development Environment (IDE) that includes a C++ compiler. The IDE and the compiler
are actually two separate pieces of software, but are installed together to make things simpler.
Both are open-source software and are distributed under the Gnu Public Licence (http://
www.gnu.org/licenses/), which means you are free to use, copy or modify them. You are not
required to register or pay for any of this software.

The IDE is called Code::Blocks (version 10.05). (See http://www.codeblocks.org/ if you want
more information.)

The compiler is the MinGW port of the Gnu Compiler Collection (version 4.4.1). (See
http://www.mingw.org/ if you want more information.)

The prescribed software is designed to work on Windows platforms (e.g. Windows XP, 7 or
8), but there are versions available for other operating systems, like Linux. Although you are
welcome to use other versions of the software, we will not be able to give you any support if
you don't use the prescribed software. Also, you must make sure that the programs you
submit for your assignments work on the prescribed software.

Installing the software


The MinGW C++ compiler is bundled with Code::Blocks, and they are installed together.

• Double-click on the "My Computer" icon on your desktop


• Right-click on your DVD icon, and select "Explore"
• Navigate to the \install\codeblocks folder
• Double-click on the file codeblocks-10.5mingw_setup.exe
• During installation, you will be asked to choose the Destination Directory where
Code::Blocks must be installed. We recommend that you accept the default
destination directory, namely C:\Program Files.

Using the software


Code::Blocks provides a friendly user interface to the MinGW C++ compiler. In fact, it will
not be necessary for you to work directly with the compiler. You can always do so by means
of Code::Blocks.

In COS1511, the programs you write will be somewhat simpler than for COS1512. In
particular, all the programs will consist of a single file, so you can get by without a project.

To help you get started we present a short guide to your first "Hello World" program.

Open Rubric
Step 1. Start Code::Blocks

During installation, a shortcut to Code::Blocks should have been placed on the desktop.
Double-click it to start Code::Blocks.

Otherwise, you can click on the Windows "Start" button and choose "CodeBlocks" on the
"Programs" submenu.

A window like the following will be displayed:


Step 2. Create a new C++ source file

To create a source file, choose "New | Empty File" on the "File" menu, or click on the "New
File" toolbar button and choose "Empty File" on the pop-up menu. An empty source file will
be displayed in the edit panel:

By the way, you can hide the Project manager (the panel on the left) by deselecting
"Manager" on the "View" menu, or by clicking on the close button (little cross) on the
"Management" panel. You won't be needing this for COS1511.

Step 3. Save the source file

Choose "Save" or "Save as" on the "File" menu, or click on the "Save" toolbar button. We
suggest that you create a separate directory (such as C:\unisa\COS1511) in which you save
all your work for a particular module. Beware: Do NOT save it in a directory (or a path) with
a space in it (such as C:\My Documents\COS1511). Navigate to the directory you've created
(if necessary) before typing the name of the source code file, e.g. first.cpp, and clicking on
the "Save" button.

The only difference you should notice is that the filename *Untitled1 has now been replaced
by your filename, e.g. first.cpp.

It may seem strange to save a file before you have typed a program, but it is a good habit to
get into.
Step 4. Edit the source file

Type in the following program in the edit panel:

Step 5. Compile the program

This is the easy part. Choose "Build" on the "Build" menu, or click on the "Build" toolbar
button. Watch the messages displayed in the "Build log" below the edit panel.

Assuming you haven't made any typing mistakes, your program should compile without any
errors. (If there are errors, they will be displayed in the "Build log".)

If you are SURE that you have typed in the program precisely correctly, but an error message
is displayed every time you compile the program, see Troubleshooting below.

Step 6. Run the program

This is the fun part. To see the fruits of your labour, either choose "Run" from the "Build"
menu or simply click on the "Run" toolbar button. If all goes well you should see a window
like this:
Press any key to close the console window.

Congratulations! You have just compiled and run a C++ program using Code::Blocks. Easy,
wasn't it?

To create a new program, close your existing program, and open a new one. To edit an
existing program (one that you worked on previously), choose "Open" on the "File" menu or
click on the "Open" toolbar button.

Troubleshooting
Make sure that your source code file is not saved in a directory (or a path) with a space in it.
We recommend that you create a directory, e.g. C:\unisa\COS1511, and save all your source
code files there.

You might also like