Saturday, August 8, 2009

How to Compile & Run C++ Program in Ubuntu linux

Well.... Compiling & running a C++ program in ubuntu linux is little bit tough. But don't worry, here I am to make it easy.
Step 1:: Put the C++ source code in a file with extension .cpp
Step 2:: Let the terminl know where you have saved the code. i.e. specify the path.
Step 3:: Write g++ filename.cpp -o test to compile it.
Step 4:: Now run it by using ./test.

You will see output of your program in terminal window.
During run time, you may have error, because coading of C++ in linux is little bizarre.
Here is the example::
#include<iostream>
main()
{
std::cout<<"testing"<<"\n";
}
Now you surely get the output.
Still getting errors??? Then make sure you have installed necessary package to run C++ program. If not, say terminal to install it by using
sudo apt-get install build-essential g++ & connect computer to internet.








How to Compile & Run C Program in Ubuntu Linux

well.... its a little bit tricky to compile C program in linux!!

Step 1:: First you have to put the source code in a file with extension .c
Step 2:: Open terminal & specify the path where you have save it.
Step 3:: Tell the gnome compiler to compile it by using gcc filename.c
Step 4:: To run the program type ./a.out

You will see the output of the program in terminal window.

If terminal fails to compile or run it make sure you have installed build-essential pack.
To get it connect your computer to Internet and put sudo aptitude install build-essential in terminal.
Still have problems..... write the source code properly.