Reputation: 116
Am stumped on an automake link. Even after pouring over the manuals for hours and searching online it is probably a misunderstanding of autotools.
I have one .la library made by libtool, one .dylib shared library and am creating a program. The .la is linked to the .dylib and the program uses the .la.
Makefile.am for the .la library
lib_LTLIBRARIES = libA.la
libA_la_LDFLAGS = ${AM_LDFLAGS} -no-undefined
libA_la_LIBADD = $(LIBM) -Ldir/to/ -lB
libA_la_CPPFLAGS = ${AM_CPPFLAGS}
Makefile.am for program with libtool wrapper
noinst_PROGRAMS = test
test_SOURCES = test_source.c
test_LDADD = libA.la -Ldir/to/ -lB
libA.la is created and links to B.dylib but the test program "wrapper" created by automake is exporting DYLD_LIBRARY_PATH
to find libA.la while not linking to B.dylib. Giving the error
dyld: Library not loaded: ./B.dylib
Referenced from: /dir/to/test/.libs/test
Reason: image not found
Trace/BPT trap: 5
Some things that I have tried are adding -Ldir/to/ -lB
to test_LDFLAGS
in addition to already being added in test_LDADD
. And have tried setting test_LDFLAGS = -rpath -Ldir/to
in the hopes that setting the runtime search path to the directory where B.dylib is would help.
If I manually export DYLD_LIBRARY_PATH
to include /dir/to/B.dylib
then the test program is able to run but I'm looking to have autotools take care of this rather than requiring someone to export a path before being able to run it.
Upvotes: 0
Views: 497
Reputation: 281
The problem is that Libtool wasn't involved in building libB.dylib, so it does not know how to fix up your environment to find it. That means it is up to you. You can add path/to/ libB in your environment, or add a hardcoded search path to libA.la so that libA will find it.
libA_la_LIBADD = $(LIBM) -Ldir/to/ -rpath dir/to/ -lB
This will not only add the path to B in libA's binary, but will add it to dependency-libs in Libtool's libA.la file so that on platforms that won't automatically inherit the rpath specification it can be added by Libtool when linking.
Upvotes: 1
Reputation: 31254
libB.dylib includes an rpath
that gets copied into your binary and that is used to resolve -lB
at runtime.
And it seems that this rpath is not /path/to
, so libB.dylib cannot be resolved by the runtime linker.
The reasons why it works for libA.la
is that libtools knows that the rpath in libA.dylib
is wrong anyhow (as you haven't done a make install
) and so it needs to be set manually.
The only way around this that i have found is to use install_name_tool
to fix the stored rpath
in the resulting binary.
(that is: I don't think that libtool
will do this for you, as it contradicts the intended use of libB.dylib
- as declared in its rpath)
Upvotes: 1