Linux FAQ - Section 5
Porting, compiling and obtaining programs


Please see also the Linux GCC-FAQ, available in HTML format by FTP from www.mrc-apu.cam.ac.uk in /pub/linux/GCC-FAQ.html.

Question 5.1. How do I port XXX to Linux ?

In general Unix programs need very little porting. Simply follow the installation instructions. If you don't know and don't know how to find out the answers to some of the questions asked during or by the installation procedure you can guess, but this tends to produce buggy programs. In this case you're probably better off asking someone else to do the port.

If you have a BSD-ish program you should try using -I/usr/include/bsd and -lbsd on the appropriate parts of the compilation lines.

Question 5.2. What is ld.so and where do I get it ?

ld.so is the dynamic library loader. Each binary using shared libraries used to have about 3K of start-up code to find and load the shared libraries. Now that code has been put in a special shared library, /lib/ld.so, where all binaries can look for it, so that it wastes less disk space, and can be upgraded more easily.

It can be obtained from tsx-11.mit.edu in /pub/linux/packages/GCC and mirror sites thereof. The latest version at the time of writing is ld.so.1.7.11.tar.gz.

/lib/ld-linux.so.1 is the same thing for ELF [Q8.2 `What's all this about ELF ?'], and comes in the same package as the a.out loader.

Question 5.3. Has anyone ported / compiled / written XXX for Linux ?

First, look in the Linux Software Map (LSM) --- it's in the docs directory on sunsite.unc.edu, and on the other FTP sites. A search engine is available on the WWW at http://www.boutell.com/lsm/.

Check the FTP sites (see Q2.5 `Where can I get Linux material by FTP ?') first --- search the find-ls or INDEX files for appropriate strings. Check the Linux Projects Map (LPM), on ftp.ix.de in /pub/Linux/docs/Projects-Map.gz.

If you don't find anything, you could either download the sources to the program yourself and compile them -- see Q5.1 `How do I port XXX to Linux ?' -- or, if it's a large package which may require some porting, post a message to the newsgroup comp.os.linux.development.apps.

If you compile a largeish program please upload it to one or more of the FTP sites and post a message to comp.os.linux.announce (submit your posting to linux-announce@news.ornl.gov).

If you're looking for an application-type program the chances are someone has already written a free verson. Try reading the FAQ in comp.sources.wanted for instructions on how to find sources.

You should also check the Projects-FAQ, available in /pub/Linux/docs/faqs/Projects-FAQ on sunsite.unc.edu.

Question 5.4. Can I use code or a compiler compiled for a 486 on my 386 ?

Yes, unless it's the kernel.

The -m486 option to GCC, which is used to compile binaries for 486 machines, merely changes certain optimisations. This makes for slightly larger binaries which run somewhat faster on a 486. They still work fine on a 386, though, with little performance hit.

However, from version 1.3.35 the kernel will use 486- or Pentium-specific instructions if configured for a 486 or Pentium, thus making it unusable on a 386.

GCC can be configured for a 386 or 486; the only difference is that configuring it for a 386 makes -m386 the default and configuring for a 486 makes -m486 the default; in either case these can be overriden on a per-compilation basis or by editing /usr/lib/gcc-lib/i*-linux/n.n.n/specs.

There is an alpha version of GCC that knows how to do optimisation well for the 586, but it is quite unreliable, especially at high optimisation settings. The Pentium GCC can be found on tsx-11.mit.edu in /pub/linux/ALPHA/pentium-gcc. I'd recommend using the ordinary 486 GCC instead; word has it that using -m386 produces code that's better for the Pentium, or at least slightly smaller.

Question 5.5. What does gcc -O6 do ?

Currently the same as -O2 (GCC 2.5) or -O3 (GCC 2.6, 2.7); any number greater than that currently does the same thing. The Makefiles of newer kernels use -O2, you should probably do the same.

Question 5.6. Where are <linux/*.h> and <asm/*.h> ?

These are in the directories /usr/include/linux and /usr/include/asm.

However they should be symbolic links to your kernel sources in /usr/src/linux and not real directories.

If you don't have the kernel sources download them --- see Q7.6 `How do I upgrade/recompile my kernel ?'.

Then use rm to remove any garbage, and ln to create the links:

   rm -rf /usr/include/linux /usr/include/asm
   ln -sf /usr/src/linux/include/linux /usr/include/linux
   ln -sf /usr/src/linux/include/asm /usr/include/asm
Nowadays /usr/src/linux/include/asm is a symbolic link to an architecture-specific asm-<arch> directory - if you have a freshly unpacked kernel source tree you must use make symlinks. You'll also find that you may need to do make config in a newly-unpacked kernel source tree, to create <linux/autoconf.h>.

Question 5.7. I get errors when I try to compile the kernel.

Make sure that /usr/include/linux and /usr/include/asm aren't actual directories but instead symbolic links to /usr/src/linux/include/linux and /usr/src/linux/include/asm respectively.

If necessary, delete them using rm and then use ln -s to make the links as in Q5.6 `Where are <linux/*.h> and <asm/*.h> ?'.

Remember that when you apply a patch to the kernel you must use the -p0 or -p1 option: otherwise the patch may be misapplied. See the manpage for patch for details.

If you're patching to a kernel more recent than 1.1.44 you should find that there are new directories /usr/src/linux/include/asm-i386. The directory asm there should be removed. The symlinks Makefile target will make these be symbolic links to asm-i36 and arch/i386/boot respectively. The easiest way to make sure all this gets done is not to try to patch 1.1.44 to make 1.1.45, but to download linux-1.1.45.tar.gz instead.

ld: unrecognised option `-qmagic' means you should get a newer linker, from tsx-11.mit.edu in /pub/linux/packages/GCC, in the file binutils-2.6.0.2.bin.tar.gz.

Question 5.8. How do I make a shared library ?

For ELF,
   gcc -fPIC -c *.c
   gcc -shared -Wl,-soname,libfoo.so.1 -o libfoo.so.1.0 *.o
For a.out, get tools-n.nn.tar.gz from tsx-11.mit.edu, in /pub/linux/packages/GCC/src. It comes with documentation that will tell you what to do. Note that a.out shared libraries are a very tricky business.

Question 5.9. My executables are (very) large.

With an ELF compiler (see Q8.2 `What's all this about ELF ?') the most common cause of large executables is the lack of an appropriate .so library link for one of the libraries you're using. There should be a link like libc.so for every library like libc.so.5.2.18.

With an a.out compiler (see Q8.2 `What's all this about ELF ?') the most common cause of large executables is the -g linker (compiler) flag. This produces (as well as debugging information in the output file) a program which is statically linked, i.e. one which includes a copy of the C library instead of using a dynamically linked copy.

Other things that are worth investigating are -O and -O2 which enable optimisation (check the GCC documentation) and -s (or the strip command) which strip the symbol information from the resulting binary (making debugging totally impossible).

You may wish to use -N on very small executables (less than 8K with the -N), but you shouldn't do this unless you understand its performance implications, and definitely never with daemons.

Question 5.10. Does Linux support threads or lightweight processes ?

As well as the Unix multiprocessing model involving heavyweight processes, which is of course part of the standard Linux kernel, there are several implementations of lightweight processes or threads, most of which are generic packages for any Unix: Please contact the authors of the packages in question for details.

Kernel version 1.3.35 contains some support for kernel threads, but this code has not been well-tested.

Question 5.11. Where can I get `lint' for Linux ?

Roughly equivalent functionality is built into the GNU C compiler (gcc) which is used by Linux systems. Use the -Wall option to turn on most of the useful extra warnings. Check the GCC manual for more details (type control-h followed by i in Emacs and select the entry for GCC).

There is a freely available program called `lclint' that does much the same thing as traditional lint. The announcement and source code are available at on larch.lcs.mit.edu in /pub/Larch/lclint; on the World Wide Web look at http://larch-www.lcs.mit.edu:8001/larch/lclint.html.

Question 5.12. Where can I find `kermit' for Linux ?

Kermit has a restrictive copyright which has forced most distribution maintainers to remove it, or to move the package containing it into an obscure directory.

The source code is available on kermit.columbia.edu in /kermit/archives/cku190.tar.gz; Linux binaries are available in /kermit/bin/ckuker.linux and /kermit/bin/ckuker.linuxtcp.


Next: Solutions to common miscellaneous problems.
Back: Linux's handling of filesystems, disks and drives.
Return to contents.

Ian Jackson / ijackson@gnu.ai.mit.edu - 06 March 1996

Extracted from Linux Frequently Asked Questions with Answers, Copyright Ian Jackson 1996.