Wednesday, August 6, 2008

installing and running gcc / g++ compiler in ubuntu

New to ubuntu? just stumbled upon installing gcc compiler and running a sample program? It's simple!

open up a terminal and write the command:

sudo aptitude install build-essential

It will automatically install gcc/g++ compiler into your system. Also you can do the same thing from the Synaptic package manager. Open the Synaptic package manager, search for a package "gcc" and then you will get the list of available packages. Just select g++ from there and install. Done !

To test it, write a simple C code like this and name it test.c:

int main()
printf("Hello ubuntu!");
return 0;

to compile it:
g++ -lm -o test.o test.c

here -lm indicates that the compiler may invoke the math library. test.o is the name of the object file.

finally, you can get the output by executing the object file:
sudo ./test.o

Here you can find details of the build-essential package: