-->
Previous Table of Contents Next


ELF Files

This version of Linux uses a new object module format called ELF, short for Executable and Linking Format. Programs compiled with ELF differ from those compiled in the older a.out format. ELF provides better support for shared libraries, the primary reason for this migration. Shared libraries save on memory usage when you run more than one program at a time, especially more than one X Window program.

Normally, you won’t have to pay attention to ELF or a.out issues, except for one thing: the a.out libraries are not compatible with the ELF libraries. This is especially true for shared libraries.

Thus, you need to be careful about any Linux binary programs you acquire. If you compile everything from source code, then you’re OK, as Linux will use the libraries you have on your system.

But if you pick up applications in precompiled binary format, for example, Netscape Navigator or NCSA Mosaic, you have to ensure that you have the proper shared libraries as expected by the application, or the program simply won’t run.

When you install Linux (or any time later if you run the setup program), you can install both the a.out and the ELF libraries. If you have the disk space, you should load both. If you need to choose one or the other, go with ELF, as everything in the Linux world is migrating to ELF.

To see what systems your linker, ld, is configured for, try the following command:


     ld -V

You should see output like the following:


     ld version cygnus-2.6 (with BFD 2.6.0.14)

       Supported emulations:

        elf_i386

        i386linux

        i386coff

        m68kelf

        m68klinux

        sun4

        elf32_sparc


NOTE:  The sparc, sun4, and m68k (Motorola 68000) are for cross-compiling. Chances are you won’t use these options.

By default, gcc will compile to ELF format. To verify, use the file command on any executable file, such as the chap10 file we created earlier:


     file chap10

You should see output like the following:


     chap10: ELF 32-bit LSB executable i386 (386 and up) Version 1

This indicates that the default object file format on Linux is now ELF, as expected.


NOTE:  The term a.out, unfortunately, means different things in different contexts. If you compile a C program with gcc, the default output filename remains a.out. Even so, this a.out file will appear in ELF object file format, not the older object file format, called a.out format. This is yet another confusing part of Linux.

If for some reason you need to force gcc to compile in a.out format, you can use the following command in place of gcc:


     gcc -b i486-linuxaout -c foo.c -o foo

This command requires the a.out libraries. If you did not load them, this command will fail.

Linux Shared Libraries

Linux supports a great concept called shared libraries. Because so many Linux programs link in very large libraries, particularly X Window libraries, the program size tends to grow. When you run these programs, they take up more memory (real and virtual). To help alleviate this problem, Linux supports shared libraries, similar to Windows DLLs, or Dynamic Link Libraries. The whole purpose is that many programs can reference a single copy of the library loaded into memory. For X Window programs, this saves a lot of RAM.

The problem with Linux shared libraries is that they are very tightly linked to their version numbers. If you upgrade your version of Linux, many old applications may still demand the old versions of the shared libraries, and you may no longer have these old versions on your system. If you have a lot of Linux programs that came only in binary format (Netscape Navigator is a common program in this category), you either need to load the old shared libraries or wait until all the programs you use get upgraded. If you have the source code for the program, you can simply recompile and relink, and everything should be OK.

Programming with X

Linux comes with a number of X Window libraries, ready both for you to program with and for you to use when compiling freeware X Window applications. Unfortunately, Linux does not come with the Motif libraries, which are necessary to compile a number of neat programs, including the Mosaic Internet browser. (You can purchase the Motif libraries from a number of third parties, though; see Appendix A for details. Or, you can try a freeware version of the Motif API, called LessTif, which is described later.)

When compiling X programs, you normally don’t have to do anything special to link, other than adding the X libraries to your cc command line. The X Window include files should be in the proper place, /usr/include/X11 (actually a symbolic link to /usr/X11R6/include/X11, but good enough for the compiler).

To compile and link an X program, you can use the following command line:


     cc -o foo foo.c -lXaw -lXt -lXext -lX11 -lSM -lICE

The -l option tells cc (really ld, as called by cc) to link in the named library. These libraries provide commonly used functions. The ones listed earlier provide X Window functions for the program. Thus, the -lXaw option tells ld to link in the Xaw library. By convention, this library file will be named libXaw.a for a static library and libXaw.so for a shared library.


NOTE:  For more information on X and Motif programming, see URL http://ourworld.compuserve.com/homepages/efjohnson/motif.htm on the World Wide Web.


Previous Table of Contents Next