Monday, 30 June 2014

Software in Linux: FOSS rocks!

Hey guys, today I will discuss about the various cool Free and Open Source Software (FOSS) available for the Linux OS. Many of them, prove to be best alternatives to those paid-software, and ensure that you will always feel like home in Linux. Also a few of them are even better than those which are used in Windows. So let us start:

The major software you need are:

KDE software are always known for their performance, beautiful interface and tonnes of other features. Though, it is highly recommended that you prefer KDE software only when you are using KDE distros like openSUSE(KDE) or Kubuntu. Also KDE software require a bit more resources than other software, but if you have a modern PC or laptop, enjoy the ride with KDE!


Office Suite:

Libre Office is an Open Source alternative to MS Office, and includes all software which you will need.
  • LibreOffice Writer is a word processing program similar to MS Word
  • LibreOffice Calc, is used for creating spread sheets, like MS Excel
  • Libre Office Impress is for presentations, just like MS PowerPoint
  • Libre Office Base is for database development, similar to MS Access

Libre Office Suite



Archiving Tool:

Forget about the annoying popups of WinRar. Linux has efficient archiving tools that keep you awestruck, and the best part is that they come preinstalled with your distro.

Web Browser:

When talking about web browsers, you don't need to worry at all, because your favourite Mozilla Firefox and Google Chrome are available in Linux. The OpenSource web browser, Chromium, from whom Chrome derives its source code, is available in the repositories, while Chrome can be downloaded from the Google website.
Personally, I would recommend Chrome to Chromium.

Email Client:

Mozilla Thunderbird makes your email-management easy because of its simple interface.
For KDE fans, Kmail is flooded with many features also.
For now, I would recommend Thunderbird.

Video Player:

Vlc media player rules the heart of many Linux users. Apart from that, we have the SMPlayer, which, I would personally recommend. These two are the best media players with built in codecs. Install both of them and you will never get trouble watching any kind of video.

SMPlayer


Music Player:

Anything is better than the “Windows Media Player”. Linux users are blessed with dozens of media players with such beautiful interface, ease of use and versatility that choosing one of them becomes very difficult. To me, Rhythmbox and Amarok(KDE) are the best of the best ones.

Amarok is better recommended for KDE users. It is a fully featured player that fetches each and every data for the tracks you play from the Internet, including album art, lyrics and even webpages!

Rhythmbox has a interface inspired by iTunes, and you will just fall in love with it. Clementine and Banshee are also worth mentioning. The rainfall-background effect in Clementine is just awesome!

Amarok


Music Tag Editor:

Hey, don't worry if you downloaded your music collection from a website with a horrible irrelevant album art and shit like metadata. 
Editing the music metadata can be done from your music player itself, but these software offer you great speed and power to edit your music metadata. Puddle Tag and Easy Tag are best ones here. I use Easy Tag. These software will help you organizing your music collection in such a way that your friends will easily get jealous.

Easy Tag


Text Editor:

Oh come on, if you see the text editors in Linux, you will come to know how much time you wasted struggling with the boring Notepad. Even the lightweight default text editor for GNOME DE has much more features than Notepad! Every distro has a default text editor which is fully featured and can be extended by using plugins.
Personally I would recommend the Sublime Text Editor. Install it and you will even forget your IDE for coding!

Sublime Text


PDF Reader:

When I was a Windows user, I always complained about the Adobe reader taking so much of my system resources just to start up!
Okular is a very powerful PDF and similar documents reader for KDE, but works nice with other DEs also. If you do not want to install Okular, don't worry, the pdf reader provided to you by your distro is also powerful enough!

Graphics:

Gwenview (KDE) is a picture viewer with a beautiful interface.
The Open Source GIMP, along with Inkscape (Vector Image Drawing Tool) and Krita (Digital Painting) are together, a good alternative to Photoshop.
Krita will make you think harder why you were stuck at the hopeless simple MS paint.
Blender, a 3d model rendering software is also available easily in Linux.
For managing your digital pictures, Shotwell and F-spot are the best ones , and if you are up to some professional editing, DigiKam(KDE picture managment software) and Darktable will win your heart!

Krita
Gwenview


Video Editing:

No match for the Kdenlive(KDE) here! Apart from that OpenShot and pitvi are also very good movie editing software.

Sound Editing:

For simple uses, the general purpose Audacity is also available here. For professional level, LMMS and Ardour Digital Work Station let you achieve superb results.

CD/DVD Burning:

Though you get a CD/DVD burning software with your distro, I would personally recommend the K3B (KDE). It has all the features that will make you forget even Nero. Though most of the CD/DVD images can be directly mounted, still if you want better performance, install AcetoneISO (The Kubuntu users will usually need this software)

Torrent Client:

Every distro has a pre-installed torrent client and they are worth to give a try! If you want a very simple and lightweight client then go with Transmission, the default client for GNOME. If you want more features, Deluge will never let you down. KDE users always have the feature rich Ktorrent client.



Virtualization Softwares:

You may have some Windows software which you can't live without. Also there are large numbers of distros that are worth trying! Then you can always have Windows as a virtual OS. Thus even if your Windows “gets infected”, your base OS remains untouched, and so does your valuable data. On the other hand you will also never miss your games, which run only in Windows.
Also having a virtualization software will let you try other various Linux distros, which is a great fun on itself.
Virtual Box and VMWare Player are two such software. I would recommend VMWare Player, which can be downloaded from their website. It is far better than Virtual Box, in case of speed, stability and robustness, though the non commercial version lacks some extra features, but we don't need to worry about them.


VMWare Player


Download Manager:

Do not worry, the default Linux network downloader “wget” is always with you. Download videos from YouTube and other large number of similar websites by the youtube-dl command, which can be installed easily.
Those who will miss their “cracked” IDM, a similar program, the Xtreme Dowload Manager (XDM) is very promising.

Webcam Software:

Cheese is the best one available in Linux that never lets you down.

Software Development:

If you are an IDE fan, then most of your favourie IDEs are also available here. Apart from that Linux has large number of other OpenSource IDEs as well. Netbeans, Eclipse, Mono, Qt creator, Octave, IPython, Kdevelop, etc, can be easily installed from the software center or from the respective websites also.

Apart from these, there are hundreds of softwares to be checked! Why don't you go and check some on your own? Don't forget to tell me about your experience, in the comments below.

As a bonus, you can try the offline English dictionary, Artha.
Also, try the Guake and Yakuake (KDE) drop down terminals which add “coolness” to your machine.

Artha


Yakuake








Friday, 27 June 2014

Exploring the Linux File Structure

Okay, so I hope you installed Linux at least as a virtual OS in your machine. Now let us explore our OS.
For understanding any OS the first thing we must get to know is its file structure. There is a big difference in the Windows file structure and the Unix ( and hence Linux ) file structure.

In Windows, the different partitions are assigned a label, say C:, D:  etc and are called “Drives”. Now in a drive you make folders and store your data there. The C: drive is where the Windows OS is installed.

Linux, on the other hand, maintains a “tree” directory structure, where the base is the root directory ( folders are better known as directories here ) and all other directories are either directly or indirectly linked to this root directory. In easy words, imagine in your hard drive, Linux makes a folder for root, named as "/", and it contains some basic folders, say A, B, C, etc. Now in these folders, many other sub-folders are there. Thus the entire structure resembles a tree.

Windows uses “\” to separate folders in a path name.
Linux uses “/” for the same purpose (recall websites also follow this convention)

Before moving further, here are some basic symbols that you always need to keep in mind:

/ (forward slash)  - represents the root directory, i.e., the top most directory of the file system. It is also used to separate directories in a path name.
~ (tilde)           - represents the home directory of a user
. (period)           - represents your current directory
.. (double period)   - represents the parent directory of the current directory

Now as we are all set, let us do a study of the root directory. The root directory or '/' in general, contains the following directory. Each directory has a name indicating its purpose. Click on the picture for a clear view:



1. /bin        : bin stands for “Binary files” or simply “Binaries”. This directory contains the executable files, what we know as “.exe” files in Windows. This  directory contains the common OS executables which are used by all users. Example are the cp (copy) command, the mv (move) command, etc.
2. /sbin        : sbin stands for “System Binaries”. It contains the system level commands, for example, fdisk ( shows and manipulates partition tables ), mkfs (command to make files system), ifconfig ( to manage network interface, similar to ipconfig in Windows), etc.
3. /etc        : It stores configuration files for different programs. Windows uses the registry, which is a database to store configuration information for the programs. Linux simply uses text files with a '.conf' extension for this purpose. This directory thus stores the “config” files. When the Unix directory structure was designed, /etc was supposed to store extra files ( hence the name  'etc' ) . So the config and other files were pushed to this directory.  But now, this directory only stores config files.
There may be other explanations also why this directory was named “etc”.
4. /dev        : It stores files containig the information about various devices in your machine and the OS, and hence the name.
5. /proc        : proc stands for “process”. Thus this directory stores information about the various processes running in your system. For example, /proc/<pid> will contain information about the process with id <pid>
6. /var        : var directory stores variable content, e.g. , it stores log files, downloaded packages and database files, mails to the system, etc.
7. /tmp        : temporary files are stored here. This directory content is deleted when the system reboots. So do not store anything in this directory. It is similar to Temp folder in Windows.
8. /usr         : usr stands for Unix System Resources. It stores user level programs, libraries etc. We will come to this later.
9. /home        : It stores the files and sub-directories for different users,i.e , your personal files and directories are stored here. It is similar to "C:\Users\" folder in Windows.
10. /boot         : Stores files necessary for the OS to boot. Thus it contains the boot loader (GRUB files in Linux). Don't mess with it, or you are doomed!
11. /lib        : lib stands for “libraries”. It starts for various shared libraries. Windows shared libraries have .dll extension. Linux uses .so extension for such files. We sill see them later in a bit more detail.
12. /opt        : It is to store optional softwares and files. If you install some software in Linux manually, you may install them here.
13. /mnt        : File systems can mounted here. We will come to this later.
14. /media    : Removable devices are mounted here,e.g., USB drives, external HDDs, etc.
15. /srv        : It stores service data.
16. /lost+found    : In Linux, every partition has a lost+found directory. Files saved during failures are store in this directory.
17. /root        : Not to be confused with the root directory ( “/” ). This is the home directory for the root user ( Administrator in Windows).


Apart from the above principle directories, some systems may have other directories too. Feel free to explore them.

Now as we are familiar with the basic directory structure, we can now make a comparative study of some basic Windows and Linux folders. Before that, have a look at my '/' directory :



usr, bin and sbin directories:

“usr” stands for “Unix System Resources”. Before the /home directory came, this was used to store user files. This may be another possible explanation for its name. Now, it stores files and directories for various application softwares, while personal user files are stored in /home.

“bin” directory stores general executables, and sbin stores system or admin level executables. Open the terminal and type in the following command:

echo $PATH

You will get an output similar to below

/usr/local/sbin: /usr/local/bin: /usr/sbin: /usr/bin: /sbin: /bin:
As you can see, there are different “bin” and “sbin” folders at various locations.They are:

/bin    : The directory to store user level basic OS commands, like command for copying, moving, listing directories, etc. In short, the general terminal commands are stored here.
/usr/bin    : It stores default application softwares installed by the system. For example, executables for you mail reader, Firefox web browser, text editor, office suite, calculator, picture viewer, settings manager (similar to Control Panel in Windows), etc.
/usr/local/bin    : The local directory is used to store contents which are not default, and hence the “/usr/local/bin” directory is to store executables for softwares that are manually installed by the user.

If we are installing some software at our own wish, then we must never install them in /usr/bin as they may get deleted without any warning when we update or upgrade our system.

In a nutshell, take /usr/local/bin and /usr/bin as C:\ProgramFiles\ and C:\ProgramFiles(x86)\ in Windows.
The sbin folders store more important software executables, meant for system management, user management etc. They are generally at “/sbin” , “/usr/sbin” and “usr/local/sbin”.

lib directories:

lib folders store shared library files, similar to .dll files in Windows.
/lib stores the system libraries, similar to C:\Windows\System32 folder in Windows.
Other lib folders may store libraries for respective application softwares.

mnt and media directories:

Both are used to mount file systems. The /mnt folder is used to mount file systems manually by the user generally from the terminal. Whereas /media is for those external file systems which automatically get mounted by the system. Thus if you plug in a pendrive with name “My_USB”, you can access its contents from /media/My_USB/
Recall again that unlike Windows, Linux doesn't have so called “drives”. Here the removable devices are “mounted” on various directories. The default are /media/ and /mnt/ directories.

The home directory:

Also represented by '~' , it is the personal directory for the  users in the system. Take it similar to C:\Users\ in Windows.
Suppose there are two users with respective usernames “alpha” and “beta”. Then the /home directory will contain two subdirectories, “/home/alpha” and “/home/beta”. Each of these subdirectories will contain directories like “Documents”, “Music”, “Videos”, “Pictures”, etc. , similar to “My Documents”, “My Music” , “My Pictures” and “My Videos” in Windows where the users will store there stuff.

Thursday, 26 June 2014

Is Linux Better ?


Well, the answer is a big YES! For the Windows and Mac OS x fans my answer may seem to be biased . Take your time to read this article and trust me, once you get to know Linux, you will never turn back.
Mac Os x is also based on Unix, and hence similar to Linux in most cases. But the obvious thing is that it is proprietary, plus the Apple hardware and products are, I think too costly for an average middle class person.



Now let us come to Windows and do a comparative study :



Security:




Whenever I think of Windows, the first thing that comes to my mind is the annoying anitivirus software, and the never ending fear of getting your PC infected no matter how regular you keep your anti-virus software updated. Well switch to Linux, and forget the terms like “malware”, “spyware”, “virus”, etc.

Linux is Open Source and gets regular security updates and patch-ups. Also its file structure doesn't allow those malicious software to play with your valuable data.



Speed:




Does you Windows gets slow down day by day ? Spending hours to just "defragment” your hard drive? Softwares like Ccleaner and TuneUp utilities can be seen in any “well maintained” Windows PC. The file management of Windows has some flaws which result in accumulation of temporary files, broken registry entries and fragmented partitions. I have seen many people using Windows saying “I need to format and reinstall Windows again, as my PC has become very slow”.

Linux beats Windows here. You will never have to worry about defragmenting your hard drive till it is 80% or more full. Also temporary files are efficiently removed by the OS itself. As Linux doesn't have any “registry”, forget about broken registry entries.



Hardware:




Linux is very flexible and promising when it comes to hardware and resource utilization. Linux will work like charm in even very old machines, thus giving them “a second life” !

Some of you people may say that Windows XP will also run better in those machines than the new versions of Windows. But do I need to mention that XP is no longer supported? In case of Linux, distros like Lubuntu and Xubuntu are very light weight, and you never have the fear of losing support.



Drivers:




In Windows, after a fresh install you need to install the drivers for each hardware, which is really tiring. Also each time you plug in a new USB drive, it takes a good time to detect and install the software for the drive. Switch to Linux and forget about drivers, as you do not need to install them at all! Linux automatically finds the peripherals in your system, just plug in and you are ready to work. Surprised?



Searching for Softwares:




Hey Windows fans, do you spend a good amount of your time over the Internet, searching and installing software ? And yet in many cases you do not trust the source, right?

Linux has a fully featured software managing tool where you can find all the software under one roof. Just click the install button and viola! Your software gets installed easily. While installing software from the software center, you also don't have to worry about the source as all the sources are verified ones.





Crapwares:




These are a real pain in the ass...in Windows, you must have to double check the installation options for a particular software so that it doesn't install any of those unwanted “toolbars” along with, in your PC. And not only toolbars crapwares include all unnecessary software that get install along with your base software.

Switch to Linux and forget about “crapwares”. Installing from the software center installs only the software you want.



Updates:




You are working on your Windows PC, and suddenly a pop up appears... “A new version of Adobe Flash Player is available, click to download now!” Start the KMPlayer, another pop up saying “A new version is available. Click to install now.” gets displayed. Are you tired of updating each and every software separately? And should I need to mention the weird long time taking Windows updates asking you to reboot every time you install them?

Get rid of this in Linux. Here you update your OS plus all the software with a single update button on the software center. And you are not asked to restart your machine provided the core system updates are not installed. Even if it asks you restart, you can keep on working easily on your PC, and restart when YOU want.



Softwares:




Let us be frank on this topic. All of the Windows users, more or less use the “cracked” versions of most of the important softwares. Also, if you want to be a “good guy” and buy licensed versions, can you estimate how much do you need to pay for the license of each major softwares like the Antivirus Software, MS Office etc. ?

Switch to Linux and feel the power of Open Source where you get professional level softwares and that too free of cost, with out any nasty trial pop ups and cracks.

A common thinking is that “Branded” softwares are better than the Open Source alternatives. But wait, this is just a naive ideology. The Open Source alternatives are more or less equally powerful and productive.

Also, most of the MS default preinstalled softwares are a real crap! Take notepad and Windows Media Player for example. I won't mention Internet Explorer as it has gone through a lot of improvements recently ;)

After all, you always search for a good text editor and a good media player. In Linux, you will not have to look outside. Linux users are very lucky in case of text editors and music players ( for videos, we always have VLC and SMPlayer )



Customization:




Linux, compared to Windows is highly customizable. There are a large number of Desktop environments (DEs) available. And if you don't like GUI at all, you can completely remove it! My last blog post has some of the pictures of the many DEs available in Linux.

So, in Linux, it is YOU who choose how your desktop looks like.



The Command Line:




The Windows Command Line, better known as the DOS prompt or the Command Prompt is lame and doesn't have that much of power. Most of the works are carried by the GUI methods.


However, in Linux you get a powerful command line which gives you full control over your system. So Linux lets you get closer to the system, which Windows will never allow.

Also the Linux command line interface is is very customizable, enabling you to change font, foreground and background colors, adding transparency and even setting up a background wallpaper ! Click on the picture below to see it :





Cool tweaks and graphical effects:




This one is my personal favourite. Are you a big fan of the transparency effect of Windows 7 ? Do you think Linux is boring ? Then you need to change your views immediately. Many of my “Windows user” category friends get jealous of me when I show them the cool desktop effects I have in my OS. In this case, once you switch to Linux, you will find Windows rather dull...


I am posting some of the pictures below which will definitely tempt you for Linux. Click on the pictures to get a better idea...













After such a long list, here are a few points when I would suggest you not to switch to Linux:


You are a hardcore gamer and use PC mostly to play games:



Due to proprietary issues, not much of the games are made for Linux. But in Linux we have a software, Wine, which allows it to run Winodws softwares smoothly in most cases. And at the extremum, we always have “Virtual Box” or the VMWare Player ;)

The same is for some proprietary Windows softwares which you always need.



Your hardware is still not supported:


Linux dosen't need external drivers because it already has the necessary modules for the hardware in your PC. Though most of the hardwares are supported, some of them are still not supported by Linux. A very common example is the rt3290 blue-tooth adapter.

But day by day, more and more hardwares are being supported and this problem will get eliminated soon.





If you have made up your mind, and all set to switch to Linux, stick by the following points:



  • Firstly , decide whether you want to install Linux along side Windows or want it to be the only OS in your PC ? I will recommend the later one because the former may give some awkward results if not done correctly.



  • Now before installing, try the Live CD of your favorite distro. A Live CD is a wonderful feature of Linux that allows you to test Linux booting from the CD itself. In this way, you can check whether your hardware is supported in Linux or not.



  • When you are done with the above points, don't haste into installing Linux and removing Windows. I strongly recommend that newbies must get to know the OS first. As you are switching from Windows to a complete different OS ( which has a different directory structure ) it is better to get yourself familiar with Linux first. Try installing Linux as a virtual OS ( using VMWare player ) in your Windows PC. Feel free to explore the directories and get yourself familiar with it.
When you are confident enough, you can move to Linux, saying good-bye to Windows forever...

Good luck !



Tuesday, 24 June 2014

The Linux Phobia - Should I switch to Linux ??


Hey guys, a very popular question that the students generally bump on during there academic years.
Generally, when the word Linux comes in our mind, we think of a nerdy OS with minimum or no GUI at all, struggling with the command line all the day!
Well guys make this clear that this is just a stereotype, and it needs to be broken. Linux is a very easy to use opensource OS, with much more customizability and security as compared to Windows.

From the very beginning, I used Windows. Since last 15 months, I am working on Linux and I am really feeling lucky to switch from Windows to Linux. Prior to switching, I had some doubts about Linux and a number of questions in my mind. These questions, more or less, are asked by all newbies. But don't worry as I am providing simple elaborated answer to them here.
Also let me tell you before hand that I am not here to criticize an OS and to blindly favour the other. Every OS has got its own pros and cons.


The first question, "What is Linux?"


Linux is an opensource free OS.  Do not worry, I am not going into its history.

When we say Linux, we mean the Linux kernel, which is the heart of that OS. Actually, the Linux operating system is made up of Linux Kernel, the GUI and the application software.

If we keep the kernel same, and change the Desktop Environment (DE or the basic GUI) we get a flavour of Linux, what we call a distribution or distro. This is the most interesting part. As the kernel source code is free, we can have a large number of distros. This may sound confusing to some newbies, but think the other way, if one distro doesn't suit you, you have the other to choose. In this way, you can choose the best which fits your needs.

Well in case of Windows, you get no such distros. We have the same kernel with the same GUI provided by MS. If we want to change the appearance we may use transformation packs there, but they are a pain in the ass to uninstall cleanly.

Some of the popular DE's are the GNOME desktop environment, Unity, Cinnamon, K Desktop Environment (KDE) and so on. Xfce is a very lightweight DE. Hence if I have a old computer such that Windows XP also denies to run smoothly in it, Xfce will work like charm. Even more lighter DE is the LXDE. Thus you run an up-to-date new OS in your old machine with the help of Linux.

Personally I prefer the KDE, which is by far the heaviest desktop environment, flooded with polished desktop tweaks, effects and customization.

Here are a few snapshots showing some of the DEs available in Linux.

[1.] The KDE ( Distro: kubuntu )

 [2.] The LXDE ( Distro: lubuntu )
 [3.] Unity ( Distro: Ubuntu )
 [4.] Xfce ( Distro : xubuntu )
 Above is a very small list of the vast options you get.


The second question, “Hey there is no such C drive, D 

drive etc. It looks so alienated!”


Well the answer is the file management techniques used by Linux. Linux uses the tree file management technique in which the “Root” directory is at the top, an all other are linked directly or indirectly to it. As we will see later, this arrangement has many advantages. For now, no need to feel alienated. In Windows, you have My Documents, My Music, My Videos etc. Here you have similar directories ( Documents, Pictures, Videos and Music) in the Home directory, where you can store your stuff.


The third question, “How can I have the necessary

software?”


This is one of the best things I like in Linux. I would answer, “Yes you will get alternatives, and in some cases better alternatives to almost all Windows software.” Also, some open source software are available for all OS's, like
in Linux, you will find Firefox, Vlc , Google Chrome,...
And if you are completely devoted to Windows software, then we have Wine, by which you can run them in Linux. Wine works well with most of the software and if there is any problem, we always have Virtual Box or the VMware player.


The fourth question, “I have seen most of the works done

 by the command line, it really haunts me.”


Hey common, told you it is just a stereotype. It is nothing like being in Linux you will have to be the master of command line. In Linux, we get a work done by either the command line or by using the GUI. The former is faster. Now you realize why the geeks are always playing with the command line.
Another thing, don't t think that Linux users are very good at complex commands. No one writes complex commands by own. We generally use the magic keys ( CTRL + C and CTRL + V).
Though when you will spend a few months with Linux, you will realize the power of the command line and hence would automatically start loving it.

Thus we see that there is nothing to fear about Linux and thus the Linux-phobia is just a stereotype. If you do not believe me, try using Linux ( in Virtual Machine ) and you will definitely fall in love with this beautiful OS.

In the next post we will discuss about the power of Linux, which is generally described by speed, security and stability with a recently added term, beauty.



 



 

The C Building Process

Hey guys, most of you might have wondered how does a C/C++ program actually get transformed into an executable code. Well, that involves a number of steps and also a few components, viz.

1. The source code – The textual version of the code, written by the programmer. It includes the C or  C++ statements, along with the preprocessor statements ( those starting with a '#' ). The source code has the extension .c or .cpp (and some other like .C, ...)
2. The Preprocessor – The source code is fed to the preprocessor, which replaces the # statements with the respective statements to form the expanded/extended source code. Generally it has the extension *.i
3. The Compiler – The *.i file is fed to the compiler, which checks the code for any syntax error , and reports error(s) if any. Remember that the compiler never checks for any dependencies or relation in the code with the other code. It will check for syntax error only. It produces the assembly code (*.asm or *.s).
4. The Assembler – The assembler converts the assembly code to “Relocatable object code” having the extension *.o or *.obj
5. The Linker – Final and one of the most important blocks of the entire procedure. It checks for the dependencies and resolves them and hence combine two or more object codes to final executable code, or the *.exe (*.out in some OS's) file.


This entire conversion from source code to executable code is called the build process.

 
Now let us take a very simple example. Here we write a small C program named “sample.c” :
We will be using linux operating system as it has simple and useful tools to show the step by step process.


Here you may stuck at two points:
  • We have not used any preprocessor statements like #include ,etc. This is just to keep the code and description simple. So remember that we can exclude preprocessing here. Hence we can save our file as sample.i which indicates that we don't need it get preprocessed.
  • There is no definition (body) of the function “func(int)”. This is to show the work of linker and compiler only. It would get clear below.

Now compile the code using following command:

gcc -c sample.c

Remember, the command “gcc -o sample.out sample.c” will do the eintire build process. But gcc with -c option only compiles and it is not linked, to produce the sample.o file (This is the object code)

Viola! Compilation was successful, though we know that the function “func” has no body, but still our code is semantically correct [correct by syntax]. Hence it was compiled properly.

Now type in your terminal the following code:

nm sample.o

The nm command shows you the symbolic version of the object code, which is supposed to be fed to the linker.
You will get the following output:



 
'U' means unresolved dependency. This shows that 'func' has an unresolved dependency.

Now try this :

gcc -o sample.out sample.c

This will do the entire build process.
As expected, you will get the following error:


ld is the GNU C linker, which when tries to find the body of 'func', inside the code and the standard C library, fails, hence, generates this error.

Hence it is the linker which searches and resolves the dependencies of the functions in our code.

Now let us come to a standard question. Why we use #include and how does this work?
Let us take #include <stdio.h>

Have you guys ever opened the file stdio.h ?

If you open it, you will find that it contains only the declaration (prototype) of the printf() or scanf() (and so on) functions. It does not contain the body of those functions. 

The compiler actually needs only the prototype, so as to check whether we are supplying correct arguments to the function or not. The compiler never checks for the body of the printf() function.
Hence, for the prototype to be included in our code, we are using the #include<stdio.h> statement.

The body of the function is in object code format, in the C library [ here it is with the GNU C library glibc ]

At the linking time, the linker searches for the body of printf() function in standard C library , which is already in object code. These object codes come with the compiler set itself.
Thus the linker when finds the object code for printf(), comnbines it with the object code of our C program to generate the final executable file.

Now what are loader and debugger??

Loader loads the executable code from the secondary memory to RAM. 

The Debugger is a feature included with the IDE in general, and helps the user to insert breakpoints in our code. The compiler compiles the code and stops at each breakpoint. This facilates in removing any user made errors (bugs) from the code, and hence the name Debugger.

Final interresting point:

Try the following code in your terminal:

objdump –disassemble sample.o

The “OBJect DUMP” command with the disassemble option shows you the object code in assembly language [Remember the *.asm or *.s file? ]



Isn't it interesting?