Discussion:
libtool libraries requiring other libraries
Steffen Sledz
2013-07-16 14:56:05 UTC
Permalink
Sorry, if this is a faq, but i didn't found a clear answer searching around.

Given situation: We have a library called e.g. libfoo which uses e.g. mq_open from librt. Than we have a program e.g. called progbar which requires libfoo (and therefor also librt).

Our current solution looks like this, but it does not work, because linking progbar is missing the -lrt option.

progbar/configure.ac:
---------------------> snip <---------------------
...
AC_CHECK_LIB([rt], [mq_open], [], [ AC_MSG_ERROR([*** Could not find librt ***]) ])
...
if test -n "$with_libfoo_path" ; then
FOO_LDFLAGS="-L$with_libfoo_path/lib -lfoo"
FOO_CPPFLAGS="-I$with_libfoo_path/include"
else
AC_CHECK_LIB([foo], [foo_init], [], [ AC_MSG_ERROR([*** Could not find libfoo, use --with-libfoo-path option ***]) ], [-lrt])
fi
AC_SUBST(FOO_LDFLAGS)
AC_SUBST(FOO_CPPFLAGS)
...
---------------------> snap <---------------------

progbar/src/Makefile.am:
---------------------> snip <---------------------
bin_PROGRAM = progbar
...
progbar_CPPFLAGS = $(FOO_CPPFLAGS)
progbar_LDFLAGS = $(FOO_LDFLAGS)
...
---------------------> snap <---------------------

Where do we have to make which checks?

Do we need a check for librt in the libfoo package?

Do we have to mention the librt link option somewhere in the progbar package?

Thx for any help,
Steffen

PS: FUP set to <***@gnu.org>
Robert Boehne
2013-07-16 15:47:35 UTC
Permalink
Steffen,

I would suggest asking questions about Libtool on a libtool mailing list.

That said - It looks to me like you're not *using* libtool to do your
linking.
Libtool's la files contain all the dependencies that a library needs.
This is a big help when using static archives because they need
to have everything listed in the proper order on the link line.
If you add

LT_INIT

to configure.ac your problem should go away.

HTH,

Robert Boehne
Post by Steffen Sledz
Sorry, if this is a faq, but i didn't found a clear answer searching around.
Given situation: We have a library called e.g. libfoo which uses e.g. mq_open from librt. Than we have a program e.g. called progbar which requires libfoo (and therefor also librt).
Our current solution looks like this, but it does not work, because linking progbar is missing the -lrt option.
---------------------> snip <---------------------
...
AC_CHECK_LIB([rt], [mq_open], [], [ AC_MSG_ERROR([*** Could not find librt ***]) ])
...
if test -n "$with_libfoo_path" ; then
FOO_LDFLAGS="-L$with_libfoo_path/lib -lfoo"
FOO_CPPFLAGS="-I$with_libfoo_path/include"
else
AC_CHECK_LIB([foo], [foo_init], [], [ AC_MSG_ERROR([*** Could not find libfoo, use --with-libfoo-path option ***]) ], [-lrt])
fi
AC_SUBST(FOO_LDFLAGS)
AC_SUBST(FOO_CPPFLAGS)
...
---------------------> snap <---------------------
---------------------> snip <---------------------
bin_PROGRAM = progbar
...
progbar_CPPFLAGS = $(FOO_CPPFLAGS)
progbar_LDFLAGS = $(FOO_LDFLAGS)
...
---------------------> snap <---------------------
Where do we have to make which checks?
Do we need a check for librt in the libfoo package?
Do we have to mention the librt link option somewhere in the progbar package?
Thx for any help,
Steffen
Steffen Sledz
2013-07-17 07:40:36 UTC
Permalink
That said - It looks to me like you're not *using* libtool to do your linking.
Libtool's la files contain all the dependencies that a library needs.
This is a big help when using static archives because they need
to have everything listed in the proper order on the link line.
If you add
LT_INIT
to configure.ac your problem should go away.
Thx. This is the solution.
Diego Elio Pettenò
2013-07-17 07:57:45 UTC
Permalink
Okay, Robert already answered but...
Post by Steffen Sledz
FOO_LDFLAGS="-L$with_libfoo_path/lib -lfoo"
[...]
Post by Steffen Sledz
progbar_LDFLAGS = $(FOO_LDFLAGS)
This is simply wrong, whether or not it works after adding LT_INIT.

-lfoo is a library not an LDFLAG.

It should be passed to _LDADD not to _LDFLAGS.

What happens is that if you pass it as LDFLAGS it's going to be
_preprended_ to the list of object files, and linkers set to link only
needed libraries will ignore it altogether.

Don't misuse LDFLAGS please. It just becomes a pain in the neck for
distributions.
--
Diego Elio Pettenò — Flameeyes
***@flameeyes.eu — http://blog.flameeyes.eu/
Satz Klauer
2013-07-18 05:35:32 UTC
Permalink
So when I understand you correct you don't want to give the option
"-lrt" again when building progbar which links against libfoo (which
itself already was linked against librt)?

In this case building libfoo needs to use this statement for linking:

-Wl,-whole-archive -lrt -Wl,-no-whole-archive

Now libfoo implicitely knows and uses dependency to librt.
Post by Steffen Sledz
Sorry, if this is a faq, but i didn't found a clear answer searching around.
Given situation: We have a library called e.g. libfoo which uses e.g. mq_open from librt. Than we have a program e.g. called progbar which requires libfoo (and therefor also librt).
Our current solution looks like this, but it does not work, because linking progbar is missing the -lrt option.
---------------------> snip <---------------------
...
AC_CHECK_LIB([rt], [mq_open], [], [ AC_MSG_ERROR([*** Could not find librt ***]) ])
...
if test -n "$with_libfoo_path" ; then
FOO_LDFLAGS="-L$with_libfoo_path/lib -lfoo"
FOO_CPPFLAGS="-I$with_libfoo_path/include"
else
AC_CHECK_LIB([foo], [foo_init], [], [ AC_MSG_ERROR([*** Could not find libfoo, use --with-libfoo-path option ***]) ], [-lrt])
fi
AC_SUBST(FOO_LDFLAGS)
AC_SUBST(FOO_CPPFLAGS)
...
---------------------> snap <---------------------
---------------------> snip <---------------------
bin_PROGRAM = progbar
...
progbar_CPPFLAGS = $(FOO_CPPFLAGS)
progbar_LDFLAGS = $(FOO_LDFLAGS)
...
---------------------> snap <---------------------
Where do we have to make which checks?
Do we need a check for librt in the libfoo package?
Do we have to mention the librt link option somewhere in the progbar package?
Thx for any help,
Steffen
_______________________________________________
https://lists.gnu.org/mailman/listinfo/libtool
Loading...