Unix Programming - question about AC_CHECK_LIB

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > January 2006 > question about AC_CHECK_LIB





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author question about AC_CHECK_LIB
gelbeiche

2006-01-13, 10:40 pm

I write a m4 macro and in this macro I try to detect
a library with AC_CHECK_LIB.
AC_CHECK_LIB($ax_lib, main, ...)
where ax_lib is my library.
The check fails because the generated code does not link
against the library.
I catched the generated code from the configure script,
tried to compile it and the linker reveals the reason:

/usr/local/lib/libboost_unit_test_framework.so: undefined reference to `init_unit_test_suite(int, char**)'
collect2: ld returned 1 exit status

libboost_unit_test_framework.so is my lib ($ax_lib) and this lib
requires some other code.

How is it possible to check the library ?

I have only the idea to look if the library axist as file in my lib-directory.
But is there a better solution ?
Roger Leigh

2006-01-13, 10:40 pm

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

gelbeiche <borstel@fliegenpilz.de> writes:

> I write a m4 macro and in this macro I try to detect
> a library with AC_CHECK_LIB.
> AC_CHECK_LIB($ax_lib, main, ...)
> where ax_lib is my library.
> The check fails because the generated code does not link
> against the library.


If you are using a C++ library, as the post implies, try something
along these lines to check if it's possible to instantiate a class
from the library:

saved_ldflags="${LDFLAGS}"
LDFLAGS="${LDFLAGS} -lboost_program_options"
AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <boost/program_options.hpp>],
& #91;boost::program_options::variables_ma
p::variables_map dummy()])],
[AC_MSG_RESULT([yes])
BOOST_LIBS="-lboost_program_options"],
[AC_MSG_RESULT([no])
AC_MSG_FAILURE([libboost_program_options (Boost C++ Libraries) is not installed, but is required by $PACKAGE])])
LDFLAGS="${saved_ldflags}"
AC_SUBST([BOOST_LIBS])

If you are doing it properly, you'd also replace the '#' with a
quadrigraph, though in this case it doesn't appear to be strictly
required. If you are mixing languages, you also want to wrap that
with AC_LANG_PUSH and AC_LANG_POP to make sure it uses the C++
variants of those macros.


Regards,
Roger

- --
Roger Leigh
Printing on GNU/Linux? http://gimp-print.sourceforge.net/
Debian GNU/Linux http://www.debian.org/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8+ <http://mailcrypt.sourceforge.net/>

iD8DBQFDxZPgVcFcaSW/uEgRAtDZAJ4u5FsA5RpZE7To4/ZUc4b1plU9dACeJ5uI
MiXY4B3Pz2TfeDv6uhwbYIU=
=4qHH
-----END PGP SIGNATURE-----
gelbeiche

2006-01-13, 10:41 pm

Roger Leigh <${rleigh}@invalid.whinlatter.ukfsn.org.invalid> writes:

> gelbeiche <borstel@fliegenpilz.de> writes:
>
>
> If you are using a C++ library, as the post implies, try something
> along these lines to check if it's possible to instantiate a class
> from the library:
>
> saved_ldflags="${LDFLAGS}"
> LDFLAGS="${LDFLAGS} -lboost_program_options"
> AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <boost/program_options.hpp>],
> & #91;boost::program_options::variables_ma
p::variables_map dummy()])],
> [AC_MSG_RESULT([yes])
> BOOST_LIBS="-lboost_program_options"],
> [AC_MSG_RESULT([no])
> AC_MSG_FAILURE([libboost_program_options (Boost C++ Libraries) is not installed, but is required by $PACKAGE])])
> LDFLAGS="${saved_ldflags}"
> AC_SUBST([BOOST_LIBS])
>
> If you are doing it properly, you'd also replace the '#' with a
> quadrigraph, though in this case it doesn't appear to be strictly
> required. If you are mixing languages, you also want to wrap that
> with AC_LANG_PUSH and AC_LANG_POP to make sure it uses the C++
> variants of those macros.
>


Good hint ! This is the way I go now.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com