[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: inter-library-dependency, how?

From: Bert Wesarg
Subject: Re: inter-library-dependency, how?
Date: Mon, 21 Nov 2011 13:10:07 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:2.0b13pre) Gecko/20110316 Thunderbird/3.3a3


Hi Nick,

thanks for the quick response.

Am 09.09.2011 18:01, schrieb Nick Bowler:

    On 2011-09-09 17:56 +0200, Christian Rössel wrote:

        I want to build a program that depends on a libtool library that depends
        on a non-libtool library that needs rpath information to be found a 

        My looks like this:
        lib_LTLIBRARIES    =
        libfoo_la_SOURCES  = libfoo.c  libfoo.h
        libfoo_la_CPPFLAGS = -I/opt/packages/papi/
        libfoo_la_LDFLAGS  = -L/opt/packages/papi/
        libfoo_la_LIBADD   = -lpapi

        bin_PROGRAMS = foo
        foo_SOURCES  = foo.c
        foo_LDADD    =


        Building and linking succeeds, but trying to run ./foo leads to
        ./foo: error while loading shared libraries: cannot open
        shared object file: No such file or directory

        The library is in the location specified by libfoo_la_LDFLAGS (.a and
        .so). But the rpath /opt/packages/papi/ is not available. How
        do I get it into foo without specifying it as
        foo_LDFLAGS = -Wl,-rpath /opt/packages/papi/

    Looking at,

       -R libdir
           If output-file is a program, add libdir to its run-time path. If
           output-file is a library, add -Rlibdir to its dependency_libs, so
           that, whenever the library is linked into a program, libdir will
           be added to its run-time path.

    So it seems that adding -R/opt/packages/papi/ to
    libfoo_la_LDFLAGS would do the trick?

Well, like the documentations says, -R/opt/packages/papi/ is
added to the dependency_libs:
dependency_libs=' -R/opt/packages/papi/
-L/opt/packages/papi/ -lpapi'

But when I link into foo, nothing is added to foo's runpath:
libtool: link: gcc -g -O2 -o foo foo.o  ./.libs/libfoo.a
-L/opt/packages/papi/ -lpapi

So, the problem remains. Any help appreciated.

Christian and I independently solved this with the following fix:

diff --git i/libltdl/config/ltmain.m4sh w/libltdl/config/ltmain.m4sh
index ca67c8a..f79ab5b 100644 libltdl/config/ltmain.m4sh
--- i/libltdl/config/ltmain.m4sh
+++ w/libltdl/config/ltmain.m4sh
@@ -6391,8 +6391,7 @@ func_mode_link ()
            # Pragmatically, this seems to cause very few problems in
            # practice:
            case $deplib in
-           -L*) new_libs="$deplib $new_libs" ;;
-           -R*) ;;
+           -L*|-R*) new_libs="$deplib $new_libs" ;;
              # And here is the reason: when a library appears more
              # than once as an explicit dependence of a library, or

With this patch, the -R flag inside the dependency_libs list is honored and appropriately added to the link command.

Is there anything wrong with this approach. If not we propose this patch for inclusion. A proper ChangeLog and Signed-of-by line will follow than. I will also try to transform Christians example into an test than.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]