autoconf
[Top][All Lists]
Advanced

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

AC_SEARCH_LIBS and two programs


From: Andrey Simonenko
Subject: AC_SEARCH_LIBS and two programs
Date: Fri, 30 Mar 2007 11:53:45 +0300
User-agent: Mutt/1.5.14 (2007-02-12)

Greetings,

There are two programs t1 and t2, one configure and
one Makefile which are used for building them.

t2 uses the cos() function, and t1 does not use cos().

This is my solution:

=======================================
configure.ac:

AC_INIT([t],[1.0])
AM_INIT_AUTOMAKE

AC_PROG_CC

back_LIBS=${LIBS}
LIBS=
AC_SEARCH_LIBS(cos, m)
cos_lib=${LIBS}
LIBS=${back_LIBS}

AC_SUBST(cos_lib)

AC_CONFIG_FILES([Makefile])

AC_OUTPUT

=======================================
Makefile.am:

AUTOMAKE_OPTIONS = foreign

bin_PROGRAMS = t1 t2

t1_SOURCES = t1.c

t2_SOURCES = t2.c

t2_LDADD = ${cos_lib}

=======================================

Now I can do the following:

% env LIBS=-lz ./configure
% ldd t1 t2
t1:
        libz.so.3 => /lib/libz.so.3 (0x800631000)
        libc.so.6 => /lib/libc.so.6 (0x800745000)
t2:
        libm.so.4 => /lib/libm.so.4 (0x800631000)
        libz.so.3 => /lib/libz.so.3 (0x80074d000)
        libc.so.6 => /lib/libc.so.6 (0x800861000)

You can see, that libm (library with cos() function) is linked
only in t2.

May be "LIBS=" in configure.ac can be removed, but in this case
I see "... -lm -lz -lz" for t2.

I've got questions.  Is there any problem in this approach?
Can the same be solved in a more correct way?

Thanks.




reply via email to

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