User Tools

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"
AC_LINK_IFELSE(
 [AC_LANG_PROGRAM([#include <artimagen.h>],
 [IM_STORE_TYPE dummy])],
 [ARTIMAGENLIB=-lartimagen],
 [AC_MSG_ERROR([libartiamgen is not installed.])])
AC_SUBST([ARTIMAGENLIB])
LDFLAGS=$SAVED_LDFLAGS
programming/cxx_lib_check_autotools.txt · Last modified: 2017/05/16 11:10 (external edit)