[Pythonmac-SIG] -R, -L, ldd, and the meaning of life...

Skip Montanaro skip@pobox.com
Thu, 10 Oct 2002 10:11:30 -0500


In much of the Unixoid world, link editors understand a -R flag and/or an
LD_RUN_PATH environment variable (or something similar).  One or the other
tell the run-time linker to search the argument director(y|ies) for shared
libraries.  For example, when linking the bsddb module, you need to tell the
linker where to find the Berkeley DB shared library.  The -L flag tells the
static linker this, but you still need some way to tell the run-time linker
(called at the time you import bsddb).  On Linux and Solaris (and probably
other platforms), at least when using the GNU tools, the -R flag serves this
purpose.

The linker in MacOSX doesn't support -R.  Does -L serve both functions,
telling both the static linker where to find libraries and recording
information in the .so file which tells the run-time linker where these
other libraries were found?  In distutils' unixccompiler module I punted on
this issue:

    def runtime_library_dir_option(self, dir):
        # XXX Hackish, at the very least.  See Python bug #445902:
        # http://sourceforge.net/tracker/index.php
        #   ?func=detail&aid=445902&group_id=5470&atid=105470
        # Linkers on different platforms need different options to
        # specify that directories need to be added to the list of
        # directories searched for dependencies when a dynamic library
        # is sought.  GCC has to be told to pass the -R option through
        # to the linker, whereas other compilers just know this.
        # Other compilers may need something slightly different.  At
        # this time, there's no way to determine this information from
        # the configuration data stored in the Python installation, so
        # we use this hack.
        compiler = os.path.basename(sysconfig.get_config_var("CC"))
        if sys.platform[:6] == "darwin":
            # MacOSX's linker doesn't understand the -R flag at all
            return "-L" + dir
        elif compiler == "gcc" or compiler == "g++":
            return "-Wl,-R" + dir
        else:
            return "-R" + dir

Was that the correct punt?

Also, is there a MacOSX equivalent of the ldd command?  On Linux and Solaris
it displays the library dependencies for a dynamically linked executable or
shared object, e.g.:

    $ ldd python
            libdl.so.2 => /lib/libdl.so.2 (0x40027000)
            libpthread.so.0 => /lib/i686/libpthread.so.0 (0x4002b000)
            libutil.so.1 => /lib/libutil.so.1 (0x4003f000)
            libm.so.6 => /lib/i686/libm.so.6 (0x40042000)
            libc.so.6 => /lib/i686/libc.so.6 (0x42000000)
            /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

Thx,

-- 
Skip Montanaro - skip@pobox.com
"Airplanes don't fly until the paperwork equals the weight of the
aircraft. Same with i18N." - from the "Perl, Unicode and i18N FAQ"