Tuesday, November 6, 2012

How to Compile a C/C++ Program on Ubuntu Linux

My step by step instructions.

1. Install the 'build-essential' package.


$ sudo apt-get install build-essential

2. Write your first C program. 
gedit myhello.c
paste this code into it, and save

#include <stdio.h>

main()
{
printf("Nothing Is Impossible!\n");
}


3. Compile your first C program

$ gcc myhello.c -o myhello


4. Run your first C program

$ ./myhello 
Nothing Is Impossible!


5. Write your first C++ program


gedit myhello.cpp


paste this code into it, and save


#include <iostream>
using namespace std;

int main()
{
cout << "Hello Ubuntu Lover in C++" << endl;
return 0;
}

6. Compile your first C++ program


g++ myhello.cpp -o myhellocpp

7. Run your first C++ program


$ ./myhellocpp 


Hello Ubuntu Lover in C++




SAGAR VASULE!

No comments:

Post a Comment