AC-Archive
Autoconf Macro Archive

ac-archive.sf.net: - Project CVS - Download
Macro Index
- AM Support
- C++ Support
- C Support
- Fortran Support
- Java Support
- Cross Compilation
- Installed Packages
- Miscellaneous
- LaTeX Support
- Uncategorized
- archive macros
- adl's macros
- bkorb's macros
- guidod's macros
- latex's macros
- other's macros
- rleigh's macros
- obsoleted macros
- released macros
- search index

Documentation
- Contribute!
- History
- acincludedir m4
- acinclude (tool)
- macro howto
- ax tricks
- maintainers
- License
- Topics

generated...
2007-08-05

(C) 2007 guidod
Download the M4 Source.

ax_cxx_check_lib

Back to the Main Page.

Synopsis
AX_CXX_CHECK_LIB(libname, functioname, action-if, action-if-not)
, 
Author

Guido U. Draheim

Category

guidod's C++ Support (released)

Documentation

The standard AC_CHECK_LIB can not test functions in namespaces. Therefore AC_CHECK_LIB(cgicc, cgicc::Cgicc::getVersion) will always fail. We need to decompose the functionname into a series of namespaces where it gets declared so that it can be used for a link test.

In the first version I did allow namespace::functionname to be a reference to a void-argument global functionname (just wrapped in a namespace) like its C counterparts would be - but in reality such thing does not exist. The only global / static functions are always made const-functions which is an attribute mangled along into the library function export name.

The normal usage will ask for a test of a class-member function which should be presented with a full function spec with arguments given in parentheses following the function name - if the function to test for does expect arguments then you should add default initial values in the prototype (even if they do not exist originally, these are used only locally to build a correct function call in the configure test script).

In the current version if you do omit the parenthesis from the macro argument then the macro will assume that you want to check for the class name - which is really to check for default constructor being exported from the given library name.

 EXAMPLE:

AX_CXX_CHECK_LIB(cgicc, [cgicc::HTTPCookie]) AX_CXX_CHECK_LIB(cgicc, [cgicc::Cgicc::getVersion () const], AX_CXX_CHECK_LIB(boost_regex, [boost::RegEx::Position (int i = 0) const])

Result: Just as the usual AX_CXX_CHECK_LIB - defines HAVE_LIBCGICC and adds the libraries to the default library path (and uses internally the normal ac_check_lib cache symbol like ac_cv_lib_cgicc_cgicc__Cgicc)

Footnote: The C++ language is not good at creating stable library interfaces at the binary level - a lot of functionality is usually being given as inline functions plus there is hardly a chance to create opaque types. Therefore most C++ library tests will only do compile tests using the header files. Doing a check_lib is however good to check the link dependency before hitting it as an error in the build later.

@vesion 2006-12-18

M4 Source Code
AC_DEFUN([AX_CXX_CHECK_LIB],
[m4_ifval([$3], , [AH_CHECK_LIB([$1])])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 $2 in -l$1], ac_Lib,
[ac_check_lib_save_LIBS=$LIBS
LIBS="-l$1 $5 $LIBS"
case "$2" 
in *::*::*\(*)
AC_LINK_IFELSE([AC_LANG_PROGRAM([
 namespace `echo "$2" | sed -e "s/::.*//"` 
 { class `echo "$2" | sed -e "s/.*::\\(.*\\)::.*/\\1/" -e "s/(.*//"` 
   { public: int `echo "$2" | sed -e "s/.*:://" -e "/(/!s/..*/&()/"`;
   };
 }
],[`echo "$2" | sed  -e "s/(.*//" -e "s/\\(.*\\)::\\(.*\\)/((\\1*)(0))->\\2/g"`()])],
	       [AS_VAR_SET(ac_Lib, yes)],
	       [AS_VAR_SET(ac_Lib, no)])
;; *::*::*)
AC_LINK_IFELSE([AC_LANG_PROGRAM([
 namespace `echo "$2" | sed -e "s/::.*//"` 
 { namespace `echo "$2" | sed -e "s/.*::\\(.*\\)::.*/\\1/"` 
   { class `echo "$2" | sed -e "s/.*:://"` 
      { public: `echo "$2" | sed -e "s/.*:://"` ();
      };
   }
 }
],[new $2()])],
	       [AS_VAR_SET(ac_Lib, yes)],
	       [AS_VAR_SET(ac_Lib, no)])
;; *::*\(*)
AC_LINK_IFELSE([AC_LANG_PROGRAM([
 class `echo "$2" | sed -e "s/\\(.*\\)::.*/\\1/" -e "s/(.*//"` 
   { public: int `echo "$2" | sed -e "s/.*:://" -e "/(/!s/..*/&()/"`;
   };
],[`echo "$2" | sed  -e "s/(.*//" -e "s/\\(.*\\)::\\(.*\\)/((\\1*)(0))->\\2/g"`()])],
	       [AS_VAR_SET(ac_Lib, yes)],
	       [AS_VAR_SET(ac_Lib, no)])
;; *::*)
AC_LINK_IFELSE([AC_LANG_PROGRAM([
 namespace `echo "$2" | sed -e "s/::.*//"` 
 { class `echo "$2" | sed -e "s/.*:://"`
   { public: `echo "$2" | sed -e "s/.*:://"` ();
   };
 }
],[new $2()])],
	       [AS_VAR_SET(ac_Lib, yes)],
	       [AS_VAR_SET(ac_Lib, no)])
;; *)
AC_LINK_IFELSE([AC_LANG_CALL([], [$2])],
	       [AS_VAR_SET(ac_Lib, yes)],
	       [AS_VAR_SET(ac_Lib, no)])
;; esac
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_CHECK_LIB