Compiling software

From MEPIS Documentation Wiki

(Redirected from Compiling)
Jump to: navigation, search

Contents

Introduction

Compiling transforms source code written in a programming language into a binary form that creates an executable program.

  • Before compiling software yourself, you might want to search for already compiled package via Synaptic. This is usually easier and most good software is available this way.
  • If the software is not available in the repos, check whether it is in Debian Testing or even Experimental. If it is there, it is often easier to install this package by MEPIS Package Building Guide.
  • For creating packages "Debian style" please use this packaging tutorial.

Preconfiguration

The trickiest part of compiling is setting up a "build environment" for the software you want to compile. This involves installing "dev" packages which contain header files for the various software libraries a package requires. If you don't have a required "dev" package, the "configure" portion of the compile will either fail, or it will configure the package without certain features which depend on those libraries. Figuring out which package to install to satisfy those dependencies can be tricky, but if you install the X, QT, and KDE development libraries, you will cover the needs of most simple programs.

In addition to these, we will install the "build-essential" package, which gives you the basic programs needed to compile. If you are compiling drivers, you will also need the kernel headers. Finally, you will also need checkinstall for creating .deb packages.

Type in terminal, as root:

apt-get install build-essential xorg-dev libqt3-mt-dev kdelibs4-dev checkinstall

For kernel headers, type in terminal, as root:

apt-get install linux-headers-$(uname -r)

Download and unpack

Download the source code from the project's website. Many open source projects are hosted on http://sourceforge.net.

You want to download the source code. Since we are compiling from source we do not need any of the *.deb, *.rpm, *.exe, or other 'precompiled binaries' available at the project website. The file usually comes in a *.tar.gz, *.tar.bz2, or *.zip format. After you download the file you need it to untar (unzip) it.

Sometimes you may want the very latest version of the program that hasn't been released yet. Developers keep the code in repositories, which allow them to make collaborative changes to the project and easily make backups. They may suggest downloading the repository version and give a line of code starting with cvs or svn. If you would like the development version, paste that line of code into your terminal to get that version (you need to have cvs or svn installed and configured on your computer)

Configure and install dependencies

Open a terminal and change directory to the new folder in which you extracted the package (you can do this by pressing F4 in file manager while you browse the folder or with the cd command) and type ls to check if you are in the right directory. Typically, there is a file called README and INSTALL or similar included. Take a brief look at these files with the less command:

less README

Press q to quit. You could also use kwrite.

Follow the instructions in these files. More often than not, they suggest the typical Unix ./configure, make, make install series of steps. The rest of this article assumes this is the case. If you see a file in the unpacked directory called CMakeLists.txt, you will want to follow the configure/build instructions for Cmake.

./configure 

or, better:

./configure --prefix=/usr 

You figure out what else you may need in the ./configure step. If you get an error that says, effectively, "you don't have this program," you need to do some fix'in. Usually it means looking for a similarly named package or a package named libpackagename or packagename-dev. "-dev" for development. If you already have it installed and the "-dev" package installed, do

./configure --help

and you can sometimes see an option to pass to the ./configure command to tell it where to look for programs. You can find the place where the files are installed with:

dpkg --listfiles packagename

or in the "Installed Files" tab of Synaptic.

Repeat ./configure until there are no errors.

Compile the program

After there are no errors, you can attempt to compile the program.

make

If all goes well, gcc will write messages all over your screen for quite a while as the magic of compilation takes place. When it has finished, check to make sure it did not end in any errors. It may be possible to continue with errors, or you may need to go back and fix them.

Install the program

Log in as root:

su (and enter your password)

Then type:

checkinstall

Follow the prompts and enter the desired info.

  • NOTE 1: the traditional command here (which will also work) is
make install

Checkinstall creates a .deb package from the compiled program and installs it. You can manage the package afterwards with the usual tools: dpkg, apt-get, KPackage, Synaptic. This way is easier to remove the package that you installed. After you are finished, you may want to move the .deb package for safe-keeping, reinstallation later, or installation on another machine.

  • NOTE 2: Checkinstall may not be available for MEPIS 7, see here.
  • NOTE 3: You can use this packaging tutorial to create proper deb packages (doesn't use Checkinstall).


You can the delete the source code directory when finished.

Links


Installing / Removing Software | FAQ | Main Page

Personal tools
In other languages