autoconf
[Top][All Lists]
Advanced

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

Re: library search test fails, please help


From: aaragon
Subject: Re: library search test fails, please help
Date: Sun, 22 Feb 2009 14:17:47 -0800 (PST)


Allan Caffee wrote:
> 
> On Sat, 21 Feb 2009, aaragon wrote:
>> I found working with autoconf sometimes very frustrating. 
> 
> Let's see if we can't change that.  :)
> 
>>This is an
>> example. I want to check for a particular static library that I created.
>> Thus, I put the following in the configure.ac file
>> 
>> AC_CHECK_LIB([cpputils], [flip],,[AC_MSG_ERROR(library cpputils not
>> found)],,)
>> 
>> The result for this test is (in config.log):
>> 
>> configure:15746: checking for flip in -lcpputils
>> configure:15781: g++-mp-4.3 -g -O3 -o conftest -g -O2
>> -I/Users/aaragon/Lib/include -L/Users/aaragon/Lib/lib conftest.cpp
>> -lcpputils   >&5
>> Undefined symbols:
>>   "_flip", referenced from:
>>       _main in ccZZadrT.o
>> ld: symbol(s) not found
>> collect2: ld returned 1 exit status
>> [...]
>> So can someone tell me why is this happening? The result of the test
>> doesn't
>> make any sense. Thanks for the help,
> 
> AC_CHECK_LIB (AFAIK) is not intended to handle static libraries.  The
> reason for this is that compilers handle static libraries quite
> differently than shared object libraries.  Compilers treat static
> libraries as a single big object file to be included along with all the
> others.  For example to compile the test program you would use something
> like:
> 
> g++-mp-4.3 -o conftest -g -O2 -I/Users/aaragon/Lib/include
> /Users/aaragon/Lib/lib/cpputils.a conftest.cpp
> 
> 

I would have never figured this out from the documentation. 


Allan Caffee wrote:
> 
> 
> I don't know of a way that's built into Autoconf to handle static libs
> this way.  The way I usually handle it is with something like this:
> 
> ## Provide commandline flags to allow users to override the default path
> ## to this static library.
> AC_ARG_WITH([cpputils],
> [AS_HELP_STRING([--with-cpputils=<DIR>],
> [override the default path to cpputils library])],
> [
> if test x"$withval" != x"no"
>       cpputils_suggested_dir=$withval;
> fi
> ],[])
> 
> AC_MSG_CHECKING([for libcpputils.a])
> if test -f "$cpputils_suggested_dir/lib/libcpputils.a"; then
>    CPPUTILS_STATIC_LIB="$cpputils_suggested_dir/lib/libcpputils.a"
>    CPPUTILS_CFLAGS="-I$cpputils_suggested_dir/include"
> else
>    CPPUTILS_STATIC_LIB="/Users/aarogon/Lib/lib/cpputils.a"
>    CPPUTILS_CFLAGS="-I/Users/aarogon/Lib/include"
> fi
> 
> Then you can just add @CPPUTILS_STATIC_LIB@ and @CPPUTILS_CFLAGS@ into
> your Makefile.in (or Makefile.am if you use Automake).  Hope that helps!
> 
> 

I understand now what you do here. When you mean add this to the
Makefile.am, you mean like in the following example? (say libxga is another
static library that depends on the cpputils library).

noinst_PROGRAMS = ga.out
ga_out_SOURCES = main.cxx
ga_out_LDADD = libxga.a @CPPUTILS_STATIC_LIB@

Now, I've been working with static libraries for no reason at all, but I
guess I could as well do it with dynamic libraries. How can I know which one
is better to use? I guess the use of static libraries will create
executables that are bigger in size, but maybe they run faster because the
linking is already done?


Allan Caffee wrote:
> 
> 
> Aside to the developers:
> 
> This seems to be a recurring issue on this list.  We should really
> document this limitation of AC_CHECK_LIB and (maybe) provide a
> replacement macro.  Thoughts?
> 
> 

Indeed, it is very annoying to find out that these macros don't work for
static libraries. I think their names should be changed accordingly. Maybe
AC_CHECK_LIB should be changed to AC_CHECK_DYNAMIC_LIB and then create
another macro AC_CHECK_STATIC_LIB that does what you suggested above or
something similar.


Allan Caffee wrote:
> 
> 
> Cheers,
> Allan
> 
> 
> 
> _______________________________________________
> Autoconf mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/autoconf
> 
> 

Thanks a lot for replying. i'll try to implement what you suggested (or come
up with dynamic libraries in my code.

aa

-- 
View this message in context: 
http://www.nabble.com/library-search-test-fails%2C-please-help-tp22140739p22152358.html
Sent from the Gnu - Autoconf - General mailing list archive at Nabble.com.





reply via email to

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