autoconf
[Top][All Lists]
Advanced

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

Re: checking twice the same library with AC_CHECK_LIB


From: Eric Blake
Subject: Re: checking twice the same library with AC_CHECK_LIB
Date: Fri, 18 Mar 2011 09:00:42 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.7

On 03/18/2011 08:50 AM, Vincent Torri wrote:
> It's not what I want. The test I want is:
> 
> 1) checking if libbfd can be used without libintl. If yes, then setting
> bfd_libs to "-lbfd"
> 
> 2) If no, then checking if libbfd can be used with libintl. If yes, then
> setting bfd_libs to "-lbfd -lintl". If not, I exit.
> 
> I want to set bfd_libs like that (because of static linking and .pc files)

Then I would suggest not using AC_CHECK_LIB, but writing lower-level
functions that don't commit a value to cache that affects a later test.

Looking at the source code, you might be able to get away with this
alternative instead (okay, so it's not really documented, and happens to
be exploiting internals of AC_SEARCH_LIBS, but if this works, it argues
that we should enhance AC_SEARCH_LIBS to accept multi-library arguments
and properly auto-append -l only when it is not already present):

AC_SEARCH_LIBS([bfd_openr], [bfd 'bfd -lintl'], [...], [...])

After all, the body of AC_SEARCH_LIBS is doing this (after temporarily
saving the original value of $LIBS):

for ac_lib in '' $2; do
  if test -z "$ac_lib"; then
    ac_res="none required"
  else
    ac_res=-l$ac_lib
    LIBS="-l$ac_lib $5 $ac_func_search_save_LIBS"
  fi
...

which ends up testing no extra libraries, then -lbfd, then -lbfd -lintl,
until the link succeeds, and only then writing the cache.

-- 
Eric Blake   address@hidden    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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