Previous Next Contents

3. Building programs

3.1 Ordinary programs

To build a program in ELF, use gcc as always. To build in a.out, use gcc -b i486-linuxaout .

$ cat >hello.c
main() { printf("hello, world\n"); }
$ gcc -o hello hello.c
$ file hello
hello: ELF 32-bit LSB executable i386 (386 and up) Version 1
$ ./hello
hello, world

This is perhaps an appropriate time to answer the question ``if a.out compilers default to producing a program called a.out, what name does an ELF compiler give its output?''. Still a.out, is the answer. Boring boring boring ... :-)

3.2 Building libraries

To build as a shared library, the basic steps look like this:

$ gcc -fPIC -c *.c
$ gcc -shared -Wl,-soname, -o *.o
$ ln -s
$ ln -s

This will generate a shared library called, and the appropriate links for ld ( and the dynamic linker ( to find it. To test, we add the current directory to LD_LIBRARY_PATH.

When you're happpy that the library works, you'll have to move it to, say, /usr/local/lib, and recreate the appropriate links. Note that the link should point to, so it doesn't need updating on every minor version number change. The link from to is kept up to date by ldconfig, which on most systems is run as part of the boot process.

$ su
# cp /usr/local/lib
# /sbin/ldconfig
# ( cd /usr/local/lib ; ln -s )

3.3 Building in a.out

You may have a need to continue to build programs in the old a.out format. For `normal' programs all you need to do to use the a.out compiler is specify the flag -b i486-linuxaout when you call gcc, and -m i386linux when (if) you call ld. If you need to build a.out DLL shared libraries still, you have my sympathy. To the best of my knowledge, the short answer is that it doesn't work. Please mail me if you know different.

Previous Next Contents