问题描述
在configure.ac中使用autoconf,我需要附加到输出变量.
Using autoconf in configure.ac I need to append to an output variable.
具体来说,我想为每个程序(Makefile.am中的myprogram1和myprogram2)以不同的方式附加到LIBS变量.假设myprogram1需要一个-lboost_python,而myprogram2需要-losg.
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.
本质上,某些程序需要某些lib,而其他程序则不需要.这是我正在做的事的一个例子.当然,AC_SUBST根据我的理解进行分配(= vs + =),所以这是行不通的.
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])])
我需要使用第一个库构建myprogram1_SOURCES并使用第二个库构建myprogram2_SOURCES.
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.
我可以使用AC_APPEND_SUBST类型的宏吗?和/或是否有更好的方法让我做需要做的事情,以构建具有链接的不同库的不同程序?
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?
推荐答案
我假设您的AC_CHECK_LIB
调用是正确的(如果不正确,您是否尝试过使用 autoconf存档(特别是 AX_BOOST_PYTHON
))?我不敢相信boost python和osg都提供了main
.
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
.
无论如何,要回答所问的问题,您不必一次全部提供AC_SUBST
'd变量的内容,因此您可以执行以下操作:
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.将库添加到程序的变量是 LDADD
或myprogram1_LDADD
.
P.S. the variable to add libraries to a program is LDADD
or myprogram1_LDADD
.
这篇关于Autoconf附加到输出变量和程序特定的LIBS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!