Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

Ubuntu 11.

10 (Oneiric Ocelot) is one of the most popular operating system for p rogramming because there are lot of great open source applications, tools, compi lers, debuggers, IDEs are available free of cost. Some of them are - GCC The gr eatest compiler for C language (from FSF ( Free Software Foundation by Stallman); L inux Torwalds used GCC while developing Linux Kernel), Eclipse IDE (The most pop ular Integrated Development Environment for Java programmers), Netbeans, KDevelop, Codelite etc. C/C++ language is a high level programming language (although the term high and low is used in relative sense e.g C is a high level language as compared to Asse mbly but if we compare it with java then C is a low level programming language; the term high or low basically describes the closeness with hardware). Most of t he operating systems has been written in C language. This post has been written for beginners who just started learning C/C++ or the programmers who have migrat ed from Windows to Ubuntu (although the commands are almost same for all Linux b ased operating system). Compiling and Executing C program in Ubuntu 11.10 1. Write and save the program Open a simple text editor (e.g gedit), IDE (Eclipse) or command line code edito r (Nano or Vim). I ll be using gedit as it is very simple to use and it s recommende d for beginner programmers. Right Click on Desktop or any directory (Browse File using Nautilus) and select create new File hello.c (.c extension is used to ind icate that it s a c program). Then write a simple program like this (and save the program press Ctrl+S) Open a simple text editor (e.g gedit), IDE (Eclipse) or command line code edito r (Nano or Vim). I ll be using gedit as it is very simple to use and it s recommende d for beginner programmers. Right Click on Desktop or any directory (Browse File using Nautilus) and select create new File hello.c (.c extension is used to ind icate that it s a c program). Then write a simple program like this (and save the program press Ctrl+S) #include<stdio.h> void main() { printf("Hello! This is my first C program with Ubuntu 11.10\n"); /* Do something more if you want */ 2. Compile the program GCC (GNU Compiler Collection) is installed by default, in Ubuntu. To compile the program, open the terminal and move on to the target directory type the command (where gcc implies compiler name, then it asks for the file name of the source program while -o option specifies the file name of the output program) gcc hello.c -o hello1 If there is no syntax/semantic error in you program then the compiler will succe ssfully generate an executable file, otherwise fix the problem in your code. 3. Execute the program To execute the program, you need to run ./hello1 Compiling and Executing C++ program The steps are almost same as above but you need to install g++ compiler, the fil e extension should be .cpp and in compilation phase replace gcc with g++. To ins tall G++ compiler, execute the command sudo apt-get install g++

If you have any problems then share it through comments. One more thing, This vi deo might help you in running your first C program in Ubuntu 11.10(I ve recorded i t in Gnome Shell interface) -

You might also like