Kim Oldfield
Presented to Linux Users of Victoria
This talk is a hands on guide for someone who has never compiled a program under linux before, or someone who has never tried to compile a package from source.
Debian packages: gcc, cpp, binutils, libc-dev. C++ programs also require: g++, and libstdc++
RedHat packages: egcs, cpp, binutils, glibc-devel. C++ programs also require: egcs-c++, libstdc++.
gcc is the standard Linux compiler, 2.7.2 is the latest stable version.
egcs is a breakaway development of gcc. This has since been renamed to gcc.
From /usr/doc/gcc/README.Debian.gz in gcc-2.95.2-0pre2:
As of gcc-2.95, optimisation at level 2 (-O2) and higher includes an optimisation which breaks C code that does not adhere to the C standard. Such code occurs in the Linux kernel, and probably other places.
There are a couple of 272 packages for Debian potato (unstable) to get around this - gcc272, gcc++272.
/* hello.c */
#include <stdio.h>
int main(int argc, char *argv[])
{
if (argc > 1)
printf("Greetings %s.\n", argv[1]);
else
printf("Please tell me your name.\n");
return 0;
}
Compile using:
> gcc -Wall -o hello hello.c
Run with:
> ./hello Linus
Greetings Linus.
gcc options
The info pages (info gcc) has much more information about gcc. These are in the gcc-doc package.
Typical Linux path:
$HOME/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin: /usr/sbin:/usr/bin:/usr/X11R6/bin:/usr/games
#!/path/interpreter
> cat > tryme <<EOF #!/bin/sh echo "This is a test script." EOF > chmod +x tryme > ./tryme This is a test script.
The easiest way to install new software:
If you are trying to compile a version which is newer than the package version you may be able to patch the new version using the old package .diff file.
Required package: dpkg-dev
Suggested packages: fakeroot, devscripts
All the debian specific files live in the debian directory.
debian/rules is a makefile which is run to build the package. It can be run directly with ./debian/rules build to compile the package, or ./debian/rules binary to compile and install the package to debian/tmp.
Download the source rpm (.src.rpm) from your local mirror.
rpm --recompile foo-ver.src.rpm
From rpm(8):
When invoked this way, rpm installs the named source package, and does a prep, compile and install. In addition, --rebuild builds a new binary package. When the build has completed, the build directory is removed (as in --clean) and the the sources and spec file for the package are removed.
Look for files called: INSTALL, README, SETUP, or similar.
Read with less docfile, or zless docfile.gz for .gz files.
Follow the instructions that come with the package. Typically they will tell you to:
Read the error messages. Look for errors about missing header files, libraries or commands.
Look at config.log if ./configure failed.
gcc may have be called with these options:
Often you may be missing a file which is required to build the package. This may be a header (.h) file, library (.a) file, or command required to build certain parts (yacc, as, g++, etc).
Header files are found in Debian packages ending -dev, or RedHat packages ending in -devel.
For example, there are three Debian libncurses4 packages:
Debian has a list of all files in all packages as part or each mirror: ftp://ftp.monash.edu.au/pub/linux/distributions/debian/dists/stable/Contents-i386.gz.
Use zgrep to search for missing files:
> zgrep ncurses.h Contents-i386.gz usr/i486-linuxlibc1/include/ncurses.h oldlibs/ncurses3.0-altdev usr/include/ncurses.h devel/libncurses4-dev
This search can also be performed on the web
Both Debian and RedHat include packages of new pre-compiled kernels, packages with the source, and Debian includes a package to help you make a package with your new kernel. The Debian packages are kernel-image-2.2.12, kernel-source-2.2.12 (the version numbers are part of the name so you can have multiple kernel sources installed at the one time), and kernel-package. The RedHat packages are called kernel, and kernel-source.
I'll assume that you don't want to use these, and show you how to compile a kernel from the original kernel source tree.
> tar -xzvf linux-2.2.13.tar.gz > cd linux
There is no easy way to find out the options used to configure your current kernel. You will need to know the type and model of the devices you wish to use.
make dep make bzImage make modules
cp arch/i386/boot/bzImage /boot/bzImage-2.2.13 make modules_install cp .config /boot/config-2.2.13 cp System.map /boot/system.map-2.2.13 vi /etc/lilo.conf lilo