|
|
Compiling Source Code ISummary:
Compiling BasicsA program is written using a programming language. Some languages, the so-called 'script languages', allow you to run written programs right away. Popular examples for these kind of languages are Perl, Python and Tcl/Tk. They come with an interpreter which serves as an translator between the program and the system. Other languages like C or C++ require the written program to be compiled to a 'binary' before it can be run. Each approach has its pros and cons: Interpreted programs require less time to develop, whereas binary programs do not need an interpreter and thus run faster, and are usually better suited for complex tasks. Compiling translates the human-readable text, the 'source', into a machine-readable file, the 'binary'. So the first thing you need for compiling is a compiler. In Linux, that's 'gcc' for programs written in C (the majority), and 'g++' (aka 'gcc-c++') for programs written in C++. When writing programs, the programmer doesn't write the whole program. He or she relies on 'libraries' which supply a set of commonly used functions. The programmer just sets a 'link' in the source file referring to a certain library or a function in that library. The compiled binary will need this library to run. You might ask yourself how you are supposed to know which libraries a program needs. The 'simplest' way would be trying to compile the source. The compilation process will bail out if it can't find a needed library. –––– Unpacking ArchivesSource is usually distributed in compressed archives. Which makes sense, since it usually contains of more than one file and compression works especially good on text files. In UNIX, these archives are created and expanded by using two different programs: one that collects all file in an archive ('tar') and one which does the compression. By convention, gzip compressed archives have the ending 'tar.gz' or 'tgz', whereas bzip2 compressed archives end on 'tar.bz2' or 'tbz2'. These archives are colloquially called 'tarballs'. To expand archives, you can either use some graphical archive manager like KDE's 'Archiver' or GNOME's 'guiTAR'. In KDE and GNOME, they should be started automatically as soon as you (double-)click on an archive file in the respective file manager. tar xzf archive for extracting gzip-compressed tar file archives, and tar xjf archive for tar files compressed with bzip2 (older version of tar might require 'y' instead of 'j'). "Pure" 'bzip2' or even 'zip' archives are quite rare in the Linux world. Unpack such archives with bunzip2 archive or unzip archive (the latter works on self-extracting '.exe' archives, too). –––– Important Files to ReadMost source archives contain files called README and INSTALL. They feature comments by the programmer on the program, how to compile it, things to watch out for and more. It goes without saying that you should read these files ;-), except if the INSTALL file begins with 'These are generic instructions', in this case the programmer couldn't be bothered to replace the file generated by 'autoconf' by something specific and helpful. –––– Needed PackagesHere's a checklist of packages you will need for compiling. Check with rpm -q name if these are installed. Compiler
System
Popular LibrariesThere are libraries which are used very often by applications. Having their development counterparts installed should get you through most compilations without errors due to missing libraries. These development libraries are the most popular with programmers. If you have them installed, you should get through most compilations without errors due to missing libraries.
There are two things to note about package names for libraries:
Now you're ready for compiling . Related Resources:–––– Comments and QuestionsThis page should mention what to do with Mandrake's own 'src.rpm' package. The urpmi man page does not make it clear. –– Mark Stosberg Revision / Modified: April 21, 2002 Legal: This page is covered by the GNU Free Documentation License . Standard disclaimers of warranty apply. Copyright LSTB and Mandrakesoft. |