我有一个用 C++ 编写的 PHP 模块,它依赖于正在安装的 C++ 库 (Boost Date_Time)。
目前,在我的 config.m4 文件中,我正在按如下方式检查库:
LIBNAME=boost_date_time
LIBSYMBOL=_ZN5boost9gregorian9bad_monthD0Ev
PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL,,
[
AC_MSG_ERROR([lib $LIBNAME not found. Try: sudo apt-get install libboost-dev])
],[
-lstdc++ -ldl
])
现在,这在我当前的环境中有效,但我痛苦地意识到这可能会在不同版本的库或编译器上中断。
如何让 automake 理解未损坏的 C++ 符号?
编辑:
我意识到检查损坏的名称很糟糕,但是是否没有某种方法可以检查“nm -C”返回的符号名称(例如 boost::gregorian::bad_month 等)。
我找到了一些对 automake 命令 AC_LANG_CPLUSPLUS() 的引用,但我不确定如何使用它以及它是否适用于此处。
最佳答案
你可以用类似的东西检查 AC_TRY_COMPILE
:
LIBNAME=boost_date_time
AC_MSG_CHECKING([for BOOST])
AC_TRY_COMPILE(
[
#include "boost/date_time/gregorian/greg_month.hpp"
],
[
boost::gregorian::bad_month* bm = new boost::gregorian::bad_month;
],
[
AC_MSG_RESULT(yes)
],
[
AC_MSG_ERROR([lib $LIBNAME not found. Try: sudo apt-get install libboost-dev])
])
这避免了使用未损坏的符号。
关于c++ - 构建 PHP 扩展时如何检查未损坏的 C++ 符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/798497/