Search code examples
c++automakephp-extensionname-mangling

How do I check for an unmangled C++ symbol when building a PHP extension?


I have a PHP module written in C++, which relies on a C++ library (Boost Date_Time) being installed.

Currently, in my config.m4 file I'm checking for the library as follows:

  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
  ])

Now, this works in my current environment, but I'm painfully aware this will probably break on a different version of the library or compiler.

How can I get automake to understand the non-mangled C++ symbol?

Edit:

I realise that checking on the mangled name is horrible, but is there not some way of checking for the symbol name as returned by "nm -C" (eg boost::gregorian::bad_month etc).

I found some refence to the automake command AC_LANG_CPLUSPLUS(), but I'm not sure how to use it and whether it's applicable here.


Solution

  • You can check AC_TRY_COMPILE with something like that:

    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])
    ])
    

    This avoid the use of unmangled symbol.