Tuesday, September 15, 2015

How to Compile a Program in Linux


> Source code is a computer program in human readable form. However, the machine
cannot execute source code. The code must be compiled into machine code before it is
use. On Linux, the "make" build system is the most common one, and this how-to
works for almost all Linux source code packages.

Steps

1. Download the source code for the program or driver from the Internet or other media.
It will most likely be in the form of a "tarball" and have a file extension of .tar, .tar.bz2,
or .tar.gz. Sometimes a .zip file will be used instead however.

2. Unpack the downloaded code:-

 A. for .zip files use - "unzip     your file"
 B. for .tgz or .tar.gz use - "tar -zxvf    yourfile"
 C. for .bz2 use " -  tar -jxvf     yourfile"

a. How untar a  "tar.xz" file ?

Ex : -
#yum install xz
(say Y to the prompt)

#unxz gcc-4.6-20110916.tar.xz
#tar -xvf gcc-4.6-20110916.tar
#xz gcc-4.6-20110916.tar  (gain to zip the tar file)

 or extract your files graphically.

3. In the terminal, move into the newly extracted directory (cd dirName).

4. Run the command "./configure" to configure the source code automatically. Arguments such as " --prefix=" can be used to control the install location. This checks that you have the right libraries and versions

5. Once configured, run "make" which does the actual compiling (this can take anything from a few seconds to many hours).An executable for the program will be created in the bin directory inside
the source code directory.

6. To install the program- run "make install".

7. You have compiled and installed the program source code.

No comments:

Post a Comment