You are on page 1of 1

Installation Procedure

By default, every ubuntu distribution such as Ubuntu 11.10 comes with gcc compiler already installed.
However, if one is not sure about this, there could be another installation. There are basically two ways of
installing C/C++ compiler on ubuntu 11.10.

The first approach is to use the build-essential. The build-essential contains a list of packages which
are essential for building Ubuntu packages including gcc compiler, make and other required tools.To install
using this approach, the following steps should be entered in the terminal.
1 sudo apt-get install build-essential

The other approach is to install gcc and g++ compiler for C and C++ separately. To install C compiler,
open the terminal and enter the command below.
1 sudo apt-get install gcc

After a successful installation, you can check the version of your compiler by entering this command in
the terminal. .

sudo gcc -v

.
Compilation and Execution of C /C++ Program
1. Write a C/C++ program
Open a simple text editor (in this case gedit) type the following codes and save as hello.c (.c extension is
used to indicate that its a c program). Or write a program and save it as hello.cpp( .cpp extension is used to
indicate that the program is c++ program)
2. To compile the program, open the terminal and move to the target directory type the command for c
program:
1 gcc hello.c -o hello
3.

For C++ program enter this in the terminal.

1
4.

g++ hello.cpp -o hello

If there is no syntax/semantic error in you program then the compiler will successfully generate an
executable file, otherwise fix the problem in your code.
1 ./hello

You might also like