OK, there's been a number of recent requests for the ability (ie
pre-canned, somehow organized ability) to check for C++ language libs.

Some quick checking shows how this is not trivial.  For example, we
could simply do this:

AC_DEFUN([AC_CXX_CHECK_LIB],
[m4_ifval([$3], , [AH_CHECK_LIB([$1])])dnl
AC_LANG_PUSH(C++)dnl
AS_LITERAL_IF([$1],
              [AS_VAR_PUSHDEF([ac_Lib], [ac_cv_lib_$1_$2])],
              [AS_VAR_PUSHDEF([ac_Lib], [ac_cv_lib_$1''_$2])])dnl
AC_CACHE_CHECK([for (allanc) $2 in -l$1], ac_Lib,
[ac_check_lib_save_LIBS=$LIBS
LIBS="-l$1 $5 $LIBS"
AC_TRY_LINK_FUNC([$2],
                 [AS_VAR_SET(ac_Lib, yes)],
                 [AS_VAR_SET(ac_Lib, no)])
LIBS=$ac_check_lib_save_LIBS])
AS_IF([test AS_VAR_GET(ac_Lib) = yes],
      [m4_default([$3], [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_LIB$1))
  LIBS="-l$1 $LIBS"
])],
      [$4])dnl
AS_VAR_POPDEF([ac_Lib])dnl
AC_LANG_POP(C++)])dnl
])# AC_CXX_CHECK_LIB

This is basically a AC_CHECK_LIB with a AC_LANG_PUSH(C++) in it. 
There's two issues here.  AC_TRY_LINK_FUNC calls AC_LANG_CALL which ends
up in a AC_TRY_LINK_FUNC for C++, but it's a verbatim copy of the C
version.

> # AC_LANG_CALL(C++)(PROLOGUE, FUNCTION)
> # -------------------------------------
> m4_copy([AC_LANG_CALL(C)], [AC_LANG_CALL(C++)])

... so the sample generated code that is linked still has the following:

> #include "confdefs.h"
> 
> /* Override any gcc2 internal prototype to avoid an error.  */
> #ifdef __cplusplus
> extern "C"
> #endif
> /* We use char because int might match the return type of a gcc2
>    builtin and then its argument prototype would still apply.  */
> char <function> ();      
> int
> main ()
> {
> <function> ();
>   ;
>   return 0;
> }

The two issues are:

1) sample code defaults back to C calls after all this trouble:
> #ifdef __cplusplus
> extern "C"
> #endif

2) very limited function-call... we can only look for a function that
looks like:
> char <function> ();      


What I'm asking is: how's the best way to go about this?  Stop the
copying of AC_TRY_LINK_FUNC(C) to AC_TRY_LINK_FUNC(C++), and generate
C++ -usable code with versatility in the function-call?  Or something
else?

Allan


Reply via email to