This is meant to be a small guide (though not exhaustive) for students beginning to program on Linux system. Particularly for those, who have done extensive C/C++ programming in Windows, using the Borland/Turbo interface or the Visual C++ interface, and are greatly intimidated by the Linux platform.

There are three major steps to program in linux

(assuming that you have thought of the algorithm you wish to implement)

  1. Coding the solution
    In windows, we have borland/turbo/Visual c++ IDE where we code, compile
    and execute our code in a single interface. In linux, these three steps
    are preformed separately (there are editors which allow you to do that
    but it is better to avoid them till one has gained enough familiarity
    with linux)
    I feel the best editor to write your code as a newbie is kate (type
    “kate &” (without quotes) on the shell prompt.
    kate is quite similar to editplus editor available on windows.
    Later on, one should move to a more powerful editor like vi or emacs (I
    personally prefer vi and nice tutor for vi can be accessed by tyoing
    vimtutor on shell prompt)
  2. Compiling the codeTo compile the code, again go to shell prompt (Yes, on linux you will soon get use to shell prompt for almost every task)
    and execute the command
    gcc progfilenameeg. gcc helloworld.c
    or g++ progfilename
    Note: gcc is C compiler for Linux (written by GNU) and g++ is C++ compiler for linux (written by GNU)
    In case there is no output => your code compiled successfully

    In case there is an output => you will see the output is readable, it tells you which lines of your code has errors/warnings.

  3. Executing the code
    Assuming that your code compiled successfully, a file named “a.out” is
    created in the same directory in which you gave the compilation command.
    Now execute the command “./a.out” (without quotes) to execute your program
    Note: In case you compile your code using -o switch you can decide the name of output file which by default, is a.out
    for example, gcc helloworld.c -o helloworld.out
    g++ helloworld.cpp -o helloworld.out

Which libraries are supported by gcc/g++ ?

gcc/g++ support almost all the libraries of borland C/C++ with one main
exception : It does not support conio.h library. Therefore, please do
not include conio.h in your source file
.

When compiling C++ source files, if you happen to use the iostream.h
header library, you may get to see some ugly warning messages by the
compiler. The program will compile fine, but if you want to get rid of
the warning messages, you can include your files in the following
manner :

#include <iostream>

#include <stdlib.h>
//… Other include statements here
using namespace std;
//this will come only in the end

instead of just

#include <iostream.h>
#include <stdlib.h>

….

Page updated by Ashish Bhatia (Y5 batch prog club coordinator) on Feb 29, 2008
Page originally written by : Shashi Mittal(Y2 batch prog club coordinator)