Originally Published: Wednesday, 4 October 2000 Author: Mike Baker
Published to: interact_articles_irc_recap/IRC Recap Page: 1/1 - [Printable]

Best of IRC for Wednesday, October 4th!

It's time once again for another edition of Best of IRC. As always we'll be taking an indepth look at some of the questions asked on #Linuxhelp. If you haven't already been to #Linuxhelp, you'll find instructions on how to get there at the bottom of the Live! page; feel free to stop by and ask questions or possibly even answer a few, we appreciate any help we can get.

   Page 1 of 1  

It's time once again for another edition of Best of IRC. As always we'll be taking an indepth look at some of the questions asked on #Linuxhelp. If you haven't already been to #Linuxhelp you'll find instructions on how to get there at the bottom of the Live! page; feel free to stop by and ask questions or possibly even answer a few, we appreciate any help we can get.

Compiling

What command do I use if I need to compile a .tgz?
<Sode> what command do I use if I need to compile a .tgz
<Sode> ?
<Ferni> Sode: you have to untar it first
<GeekGrrl> Soden: so... you unpacked the thing to a directory....? did cd that-directory... and in there a ./configure?
<Soden> umm
<GeekGrrl> Soden: basically it comes down to going into the directory and doing ./configure, make and make install
<Soden> those the basic install commands?
<Dazman> ./configure && make && make install

Often, I hear the question asked as to why programs can't just be downloaded and run directly; why they have to be compiled at all. It seems people don't understand the significance of source code, either that or they don't know what to do with it. The fact that programs are distributed in source form is less a tribute to Unix but instead the multi-architecture environment that Unix clones enjoy; source can work on any system, one binary cannot.

So, what do you do with this .tar.gz file you have before you? The first thing you'll need to do is extract it, .tar.gz stands for a gzip'd tar file. The gzip program is for compression, tar is a way to merging multiple files into one; basically you have the Unix equivalent of a .zip file. The way you uncompress this file is through the use of the tar -zxvf <file> command. The -zxvf are options that tell the tar program what to do:

-z run the program through unzip
-x extract files
-v be verbose, say what's happening
-f <file> filename to be read

tar -zxvf myfile.tar.gz

As the file is being uncompressed you'll see the file names being created scroll by. After tar is done uncompressing you'll want to cd into that directory and have a look around. You'll find that most sources include either an INSTALL or README file that says how compile the program, typically something like this:

./configure
make
make install

The dot-slash before the configure is important, it forces the command to be run from the current directory. Otherwise, you'll get a command not found error. It's the job of configure to find out what your system is capable of. When you run configure it will attempt to compile small programs to test various libraries on the system.

A library for those unfamiliar is the name for a reusable piece of codeł about the equivalent of a windows .dll. Libraries come in two parts. There's the shared object (.so) file in a /usr/lib which is the actual code for the library, then there's the header file (.h) file in /usr/include that tells the compiler how to actually use the library. If you get errors about being unable to find a particular library, it may be due to the header file for that library not being installed.

Getting back to the compile, once the make program succeeded in finding all the libraries required to compile the program, a Makefile is generated. A Makefile is a set of compile commands, it tells the compiler what needs to be compiled and in what order. These Makefiles are interpreted and run by the make command which will execute the required compile comands. The make install command is just the same program but with an argument telling it that it should follow the rules for installing.

So where is my program? The default location for installed programs is relative to /usr/local, meaning you'll probably find your program in /usr/local/bin. If you'd rather have your program installed in /usr/bin you can do so by adding this argument to the configure command.

./configure --prefix=/usr

So there we have it: Four easy commands that will help you get most programs compiled. You'll probably find that there are a few things out there that don't compile in this methood, for example the kernel. I'm not going to get into a long discussion about how to compile the kernel since there's already a HOWTO on the subject. The basic differences are "./configure" gets replaced by a command called "make menuconfig," and you'll need to run "make modules modules_install" after "make install."

hash

Why does bash say 'command not found' even though the program is in my path?
<agate> I just removed an old rpm of timidity and compiled the program again from source, the program is in /usr/local/bin/timidity yet when I try to run the program it says /usr/bin/timidity not found ???
<MbM> 'hash -r timidity' should fix your problem.

The key to the answer here is that the program had recently been uninstalled, presumably from /usr/bin. The bash shell keeps a hash table of frequently used commands; sort of a quick reference guide. If you type hash at the prompt you'll see that it has recorded the locations of frequently used commands in an effort to speed up execution. The problem you're seeing here is that the command has moved and hash doesn't know about its new location. The solution is easy enough, just remove the hash entry with hash -r.





   Page 1 of 1