255 lines
12 KiB
HTML
255 lines
12 KiB
HTML
<!--startcut ==========================================================-->
|
|
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
|
<html>
|
|
<head>
|
|
<title>Compiling Programs on Linux LG #38</title>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
|
<meta name="GENERATOR" content="Mozilla/4.5 [en] (Win98; I) [Netscape]">
|
|
<meta name="AUTHOR" content="JC Pollman">
|
|
<meta name="CREATED" content="19990207;6514800">
|
|
<meta name="CHANGEDBY" content="JC Pollman">
|
|
<meta name="CHANGED" content="19990208;20494500">
|
|
<style>
|
|
<!--
|
|
@page { size: 21.59cm 27.94cm; margin-left: 3.18cm; margin-right: 3.18cm; margin-top: 2.54cm; margin-bottom: 2.54cm }
|
|
-->
|
|
</style>
|
|
</head>
|
|
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#0000AF"
|
|
ALINK="#FF0000">
|
|
<!--endcut ============================================================-->
|
|
|
|
<H4>
|
|
"Linux Gazette...<I>making Linux just a little more fun!</I>"
|
|
</H4>
|
|
|
|
<P> <HR> <P>
|
|
<!--===================================================================-->
|
|
|
|
<center>
|
|
<H1><font color="maroon">Compiling Programs on Linux</font></H1>
|
|
<H4>By <a href="mailto:jpollman@imcnet.net">JC Pollman</a></H4>
|
|
</center>
|
|
<P> <HR> <P>
|
|
|
|
|
|
<div STYLE="margin-bottom: 0.00cm"><font color="#000000">So you are a linux
|
|
newbie and want to get your hands dirty. Most of you, myself included,
|
|
are not programmers, but that does not mean we can not enjoy the benefits
|
|
of open source, and even contribute to the cause. It also means that we
|
|
are at a distinct disadvantage when compiling goes wrong. Compiling is
|
|
usually very simple: nothing to get worried about and certainly nothing
|
|
as hard as programming, but it is not a 100% guaranteed event. What follows
|
|
is a beginner's guide to compiling. It is meant to be a 90% solution for
|
|
people starting out with linux.</font></div>
|
|
|
|
|
|
<p STYLE="margin-bottom: 0.00cm">Sooner, or later, everyone will download
|
|
a program in source code and try to compile it. Even if you are avid follower
|
|
of Red Hat or Debian, you will eventually find a program that is either
|
|
too old, or too new, to find a precompiled binary. The bad news is that
|
|
the code will not always compile no matter what you do - remember, most
|
|
linux programs are beta at best. The good news is that the percentage of
|
|
programs that compile without problems has increased significantly over
|
|
the past five years, and that there are things you can do to "fix" code
|
|
that will not compile without being a programmer.
|
|
|
|
<p STYLE="margin-bottom: 0.00cm"><b>After you download</b>: you now have
|
|
some sort of tarball on your disk. First you must uncompress it and untar
|
|
it to a directory. By convention, most people untar programs to the directory:
|
|
/usr/src. This keeps everything in one place so you can clean it after
|
|
time, as well as keep track of which version of the program you have compiled.
|
|
You will need to be root to use this directory. The linux tar program can
|
|
uncompress and untar a file at the same time if the file was compressed
|
|
using gzip. If you have a file named: filename.tar.gz, you can cd to the
|
|
/usr/src directory and type:
|
|
|
|
<p STYLE="margin-bottom: 0.00cm"><i> tar -xzvf /{path
|
|
to file}/{filename.tar.gz} <font color="#FF0000">[Enter]</font></i>
|
|
|
|
<p STYLE="margin-bottom: 0.00cm">and it will uncompress and untar. Here
|
|
is a quick explanation of the flags:
|
|
<p> x - untar the file
|
|
<br> z - uncompress the file
|
|
<br> v - verbose - so you can see what is happening
|
|
<br> f - what follows is the file you want to untar
|
|
|
|
<p STYLE="margin-bottom: 0.00cm">If you used Netscape to download the file,
|
|
you might get an error. Sometimes Netscape will uncompress the file for
|
|
you. So if you try to untar it as listed above you might see:
|
|
<div STYLE="margin-bottom: 0.00cm"></div>
|
|
|
|
|
|
<p STYLE="margin-bottom: 0.00cm"> gzip: stdin: not in
|
|
gzip format
|
|
<div STYLE="margin-bottom: 0.00cm"> tar: Child returned
|
|
status 1</div>
|
|
|
|
<div STYLE="margin-bottom: 0.00cm"> tar: Error exit delayed
|
|
from previous errors</div>
|
|
|
|
<div STYLE="margin-bottom: 0.00cm"></div>
|
|
|
|
|
|
<p STYLE="margin-bottom: 0.00cm">Try the same command, but leave out the
|
|
z. So it looks like this:
|
|
|
|
<p STYLE="margin-bottom: 0.00cm"><i> tar -xvf /{path
|
|
to file}/{filename.tar.gz} <font color="#FF0000">[Enter]</font></i>
|
|
|
|
<p STYLE="margin-bottom: 0.00cm">Instead of gzip, many files are using
|
|
bzip2 for the compression, so your file will look like: the-program.tar.bz2.
|
|
The z flag for tar will not work. The easiest way to untar the file is
|
|
to type: bunzip2 the-program.tar.bz2. This will give you the file: the-program.tar,
|
|
which you can untar using:
|
|
<div STYLE="margin-bottom: 0.00cm"></div>
|
|
|
|
|
|
<p STYLE="margin-bottom: 0.00cm"><i> tar -xvf /{path
|
|
to file}/{filename.tar.gz} <font color="#FF0000">[Enter]</font></i>
|
|
|
|
<p STYLE="margin-bottom: 0.00cm"><b>After untaring</b>: cd to the directory
|
|
that was created when you untared the program. Look at the files in the
|
|
directory: ls. You have to read the README and INSTALL files. Do not think
|
|
you will get the slightest bit of help from anyone if you do not read these
|
|
files. There is a reason why RTFM is one of the most common expressions
|
|
on the net. The README and INSTALL files should tell you how to compile
|
|
and install the program.
|
|
|
|
<p STYLE="margin-bottom: 0.00cm">To compile, you issue the "make" command.
|
|
In order for "make" to start compiling, it must have a file named: Makefile
|
|
(you could issue "make" options on the command line, but that is beyond
|
|
the scope of this article.) There are three common ways to start the compile:
|
|
simple, Imake, and configure.
|
|
|
|
<p STYLE="margin-bottom: 0.00cm"><b>Simple compile</b>: If you see is a
|
|
file called Makefile - no Imake or configure files, you are going to use
|
|
this method to compile. This method of compiling has the most problems
|
|
because nothing is configured to your computer. Often times the README
|
|
and INSTALL files will tell you to edit some files so it will compile.
|
|
Usually you can then type:
|
|
|
|
<p STYLE="margin-bottom: 0.00cm"><i> make <font color="#FF0000">[Enter]</font></i>
|
|
<div STYLE="margin-bottom: 0.00cm"><i> make install <font color="#FF0000">[Enter]</font></i></div>
|
|
|
|
|
|
<p STYLE="margin-bottom: 0.00cm">and if all goes well, you can now run
|
|
the program.
|
|
|
|
<p STYLE="margin-bottom: 0.00cm"><b>Imake</b>: If you ls the directory
|
|
and there is an Imake file and no Makefile, you use this method. This is
|
|
an older way to setup the compiling. Basically, you type:
|
|
|
|
<p STYLE="margin-bottom: 0.00cm"><i> xmkmf <font color="#FF0000">[Enter]</font></i>
|
|
<div STYLE="margin-bottom: 0.00cm"><i> make <font color="#FF0000">[Enter]</font></i></div>
|
|
|
|
<div STYLE="margin-bottom: 0.00cm"><i> make install <font color="#FF0000">[Enter]</font></i></div>
|
|
|
|
|
|
<p STYLE="margin-bottom: 0.00cm"><b>Configure</b>: Use this method of compiling
|
|
if there is a file named configure in the directory. This is the easiest
|
|
way to compile and probably has the highest chance of compiling correctly.
|
|
Essentially it checks your entire system for every possible library and
|
|
support file to ensure you can compile the program, and then creates the
|
|
Makefiles with the correct information. To compile, type:
|
|
|
|
<p STYLE="margin-bottom: 0.00cm"><i> ./configure <font color="#FF0000">[Enter]</font></i>
|
|
<div STYLE="margin-bottom: 0.00cm"><i> make <font color="#FF0000">[Enter]</font></i></div>
|
|
|
|
<div STYLE="margin-bottom: 0.00cm"><i> make install <font color="#FF0000">[Enter]</font></i></div>
|
|
|
|
|
|
<p STYLE="margin-bottom: 0.00cm">Notice the ./ in front of the first command.
|
|
When you type a command, you shell looks for the files in your path. It
|
|
does not start looking in your current directory, so if ./ (which means:
|
|
current directory) is not in your path, even though ls can see the file,
|
|
your shell can not it. The shell can execute make because it is usually
|
|
in /usr/bin which is in your path. To see your path, type:
|
|
|
|
<p STYLE="margin-bottom: 0.00cm"><i> echo $PATH <font color="#FF0000">[Enter]</font></i>
|
|
|
|
<p STYLE="margin-bottom: 0.00cm">If things go wrong:
|
|
|
|
<p STYLE="margin-bottom: 0.00cm">The most common cause of not compiling
|
|
is missing files. Almost all programs rely on support programs/files/libraries.
|
|
If they are missing, the program can not compile. The README/INSTALL files
|
|
should have told you which files, and which version of the files, you need
|
|
to compile the program. Note: the wrong version will kill you just as much
|
|
as not having it at all. Usually you will know if this is the problem because
|
|
the error statement at the end of the compile will tell you it can not
|
|
find a certain file. Note: sometimes you have the file, but it is not where
|
|
the Makefile says it is. Use your linux distribution install program, e.g.
|
|
rpm, and check to see if you have the missing file. If not, go get it.
|
|
If you do have it, and it is the correct version, check the Makefile to
|
|
see where it thinks the file is. Example: say the file moc is in /usr/local/bin,
|
|
but the Makefile says: moc=/opt/bin/moc. Then just edit the Makefile (with
|
|
vi or whatever you use for text editing) and change where moc is located.
|
|
|
|
<p STYLE="margin-bottom: 0.00cm">The next most common problem is missing
|
|
include files. Most of the files in the program source directory have lines
|
|
near the top that look something like this:
|
|
|
|
<p STYLE="margin-bottom: 0.00cm"> #include <gtk/gtk.h>
|
|
<div STYLE="margin-bottom: 0.00cm"> #include <netinet/in.h></div>
|
|
|
|
<div STYLE="margin-bottom: 0.00cm"> #include <arpa/inet.h></div>
|
|
|
|
<div STYLE="margin-bottom: 0.00cm"> #include <stdlib.h</div>
|
|
|
|
|
|
<p STYLE="margin-bottom: 0.00cm">These "h" files (or headder files) must
|
|
exist on your computer. As a minimum, check that you have the kernel headder
|
|
files by: ls /usr/include/linux. If you have installed libraries, like
|
|
gtk, make sure you have also installed the devel files for them as well.
|
|
Sometimes having multiple versions of the same library can cause problems
|
|
as each version could put its header files in different places and you
|
|
will not know which files the compile will use.
|
|
|
|
<p STYLE="margin-bottom: 0.00cm">If you have made all the necessary changes
|
|
to the Makefiles and have all the libraries and include files and it still
|
|
will not compile do the following IN ORDER:
|
|
|
|
<p STYLE="margin-bottom: 0.00cm">1. If you downloaded the program from
|
|
a site other than the home site for this program, go to the home site and
|
|
see if there is a newer version available.
|
|
|
|
<p STYLE="margin-bottom: 0.00cm">2. Go to <a href="http://www.dejanews.com/">www.dejanews.com</a>
|
|
and search for your program. It is very likely that others have had the
|
|
same problem and posted solutions.
|
|
<p>3. If all else fails, email the author. Most program authors are very
|
|
interested in improving their program and bug reports/suggested improvements
|
|
are usually well received (remember: this is linux, not commercial software.)
|
|
Note: your bug report had better say something more than "it did not compile"!
|
|
I usually email the last 10, or so, lines from the xterm compile window
|
|
so the author can see exactly where it died. If I really like the program,
|
|
I will email the author after every new version and give him/her as much
|
|
useable feedback as I can. Please note: programmers are humans too - they
|
|
go on two week vacations, change jobs and locations, and some even have
|
|
to go to class once in a while, so do not expect an immediate reply.
|
|
|
|
<p STYLE="margin-bottom: 0.00cm">Lastly, there are some programs that have
|
|
unique compile setups: qt and the kernel come immediately to mind. To compile
|
|
them, I will beat the horse one last time: read the README and INSTALL
|
|
files!
|
|
<br>
|
|
|
|
<!--===================================================================-->
|
|
<P> <hr> <P>
|
|
<center><H5>Copyright © 1999, JC Pollman <BR>
|
|
Published in Issue 38 of <i>Linux Gazette</i>, March 1999</H5></center>
|
|
|
|
<!--===================================================================-->
|
|
<P> <hr> <P>
|
|
<A HREF="./index.html"><IMG ALIGN=BOTTOM SRC="../gx/indexnew.gif"
|
|
ALT="[ TABLE OF CONTENTS ]"></A>
|
|
<A HREF="../index.html"><IMG ALIGN=BOTTOM SRC="../gx/homenew.gif"
|
|
ALT="[ FRONT PAGE ]"></A>
|
|
<A HREF="./cooper.html"><IMG SRC="../gx/back2.gif"
|
|
ALT=" Back "></A>
|
|
<A HREF="./gm.html"><IMG SRC="../gx/fwd.gif" ALT=" Next "></A>
|
|
<P> <hr> <P>
|
|
<!--startcut ==========================================================-->
|
|
</BODY>
|
|
</HTML>
|
|
<!--endcut ============================================================-->
|