问题
Using autoconf in configure.ac I need to append to an output variable.
Specifically I want to append to the LIBS variable differently for each of my programs (myprogram1 and myprogram2 in the Makefile.am). Lets imagine myprogram1 requires a -lboost_python and myprogram2 requires -losg.
Essentially some programs require certain libs while others do not. Here is an example of what I am doing. Of course AC_SUBST does an assignment (= vs +=) from what I understand so that doesn't work.
AC_CHECK_LIB([boost_python], [main], [AC_SUBST([myprogram1_LIBS], ["-lboost_python"])
AC_DEFINE([HAVE_LIBBOOST_PYTHON], [1], [Define if you have libboost_python])],
[AC_MSG_FAILURE([boost_python library not found])])
AC_CHECK_LIB([osg], [main], [AC_SUBST([myprogram2_LIBS], ["-losg"])
AC_DEFINE([HAVE_LIBOSG], [1], [Define if you have libosg])],
[AC_MSG_FAILURE([osg library not found])])
What I need is for the myprogram1_SOURCES to be built with the first lib and the myprogram2_SOURCES to be built with the second lib.
Is there an AC_APPEND_SUBST type macro I can use? And/or is there a better way for me to do what I need to do to build different programs with different libraries being linked?
回答1:
I assume that your AC_CHECK_LIB
calls and such do the right thing (if they don't, have you tried using the macros from the autoconf archive (specifically AX_BOOST_PYTHON))? I can't believe that both boost python and osg provide main
.
Anyway, to answer the question as asked, you don't have to provide the contents of an AC_SUBST
'd variable all at once, so you can do stuff like this:
myprogram1_LIBS=""
AX_BOOST_PYTHON
myprogram1_LIBS="$myprogram1_LIBS $BOOST_PYTHON_LIB"
# ...
AC_SUBST([myprogram1_LIBS])
P.S. the variable to add libraries to a program is LDADD or myprogram1_LDADD.
回答2:
once you add myprogram3 that depends on both osg
and boost
you might find it more convenient to separate the checks for libraries from their usage.
e.g. use configure
only to determine what is there, and use Makefile
to construct the proper compilation commands.
e.g. (configure.ac):
AC_CHECK_LIB([boost_python], [main], [AC_SUBST([BOOST_LIBS], ["-lboost_python"])
AC_DEFINE([HAVE_LIBBOOST_PYTHON], [1], [Define if you have libboost_python])],
[AC_MSG_FAILURE([boost_python library not found])])
AC_CHECK_LIB([osg], [main], [AC_SUBST([OSG_LIBS], ["-losg"])
AC_DEFINE([HAVE_LIBOSG], [1], [Define if you have libosg])],
[AC_MSG_FAILURE([osg library not found])])
and (Makefile.am)
myprogram1_LDADD = @BOOST_LIBS@
myprogram2_LDADD = @OSG_LIBS@
myprogram3_LDADD = @BOOST_LIBS@ @OSG_LIBS@
来源:https://stackoverflow.com/questions/14416072/autoconf-append-to-output-variable-and-program-specific-libs