Petr Cizmar's Wiki

Site Tools

programming:cxx_lib_check_autotools

Checking for a C++ library with Autotools

Check for a C++ library is not always easy using autotools. It is because C++ mangles the symbol names and thus the C++ functions cannot be called from C programs. The solution is to run one's own test.

In the ARTIMAGEN library, most of the methods are part of classes, which are part of a namespace. This and the name mangling are probably the reasons, why the traditional AC_CHECK_LIB macro doesn't work.

This problem can be solved using one's own test. The following example is taken from gAIG's counfigure.ac file. It tests for the header file, tries to declare a variable with a library-specific type and finally attempts to link with the library.

AC_LANG(C++)
SAVED_LDFLAGS=$LDFLAGS LDFLAGS="$LDFLAGS -lartimagen"
LDFLAGS=\$SAVED_LDFLAGS