如何在 ax_boost_base 中使用 HAVE_BOOST

How to use HAVE_BOOST in ax_boost_base

ax_boost_base page表示设置HAVE_BOOST。所以我在我的 configure.ac 文件中尝试了它:

AX_BOOST_BASE([1.48],, [AC_MSG_ERROR([libfoo needs Boost, but it was not found in your system])])
AC_MSG_NOTICE(["HAVE_BOOST value"])
AC_MSG_NOTICE([$HAVE_BOOST])

当我运行configure时,HAVE_BOOST似乎没有任何价值:

checking for boostlib >= 1.48 (104800)... yes
configure: "HAVE_BOOST value"
configure:

如何在我的 configure.ac 中使用这个 HAVE_BOOST?具体来说,如果设置了 HAVE_BOOST,我想将一个文件附加到我的 AC_OUTPUT 中。比如HAVE_BOOST没有设置,那么我要:

AC_OUTPUT([
Makefile 
include/Makefile
comm/Makefile
ordinary_app/Makefile
])

但是如果设置了HAVE_BOOST,那么我想要这个:

AC_OUTPUT([
Makefile 
include/Makefile
comm/Makefile
ordinary_app/Makefile
boost_enabled_app/Makefile

您错过了将结果设置回某个变量的操作。你可以试试这个

AX_BOOST_BASE([1.48],
[have_boost=yes],
[AC_MSG_ERROR([libfoo needs Boost, but it was not found in your system])]
)
AC_MSG_NOTICE(["have_boost value"])
AC_MSG_NOTICE([$have_boost])

HAVE_BOOST 在 m4 宏中设置 ax_boost_base 使用将在 config.h 中生成的 AC_DEFINE。它不是 shell 变量。 最终你可以使用 var $have_boost 来得到你想要的

if test "$have_boost" != yes; then
    AC_OUTPUT([
    Makefile 
    include/Makefile
    comm/Makefile
    ordinary_app/Makefile
    ])
else
    AC_OUTPUT([
    Makefile 
    include/Makefile
    comm/Makefile
    ordinary_app/Makefile
    boost_enabled_app/Makefile
    ])
fi