Tracking Down Problems

When tracking down problems with Babel libraries, to UNIX tools nm and ldd are your friends. nm will print the list of linker symbols in a file, including details such as whether the symbol is defined or not. ldd lists dynamic dependencies of a shared libraries or executables, indicating where it will look for these symbols when loaded.

Recall the Fortran hello world example in section 16.2.1. Even though we may think this is all done with static linking, using these tools we find out the truth.

% ldd a.out
        libg2c.so.0 => /usr/local/gcc/3.2/lib/libg2c.so.0 (0x400180000)
        libm.so.6 => /lib/i686/libm.so.6 (0x4004a000)
        libgcc_s.so.1 => //usr/local/gcc/3.2/lib/libgcc_s.so.1 (0x4006d000)
        libc.so.6 => /lib/i686/libc.so.6 (0x40076000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

Here, we clearly see that five libraries are shared libraries that will be loaded after the executable is invoked, but before we get to the main program. Some of these libraries make sense: libg2c is a Fortran to C support library, libc is the C standard library, but why is libm listed... its a library of transcendental functions (e.g. sin(), cos()) why would it be included? The answer becomes obvious when using ldd on libg2c. The Fortran support library has dependencies on the math library, so our Fortran executable inherits that dependency too.

% nm a.out | grep ' U '
        U __cxa_atexit@@GLIBC_2.1.3
        U __libc_start_main@@GLIBC_2.0
        U do_lio
        U e_wsle
        U exit@@GLIBC_2.0
        U f_exit
        U f_init
        U f_setarg
        U f_setsig
        U s_stop
        U s_wsle

nm (and grep) shows us 11 symbols that are were left undefined in our final hello world application. A little more nm|greping about will help us find that symbols starting with f_ are defined in libg2c.



babel-1.4.0
users_guide Last Modified 2008-10-16

http://www.llnl.gov/CASC/components
components@llnl.gov