Last Updated: February 25, 2016
·
515
· rhdunn

autoconf check for a specific function signature

If you need to check for a function with a specific signature (if the signature changed without any other way of detecting it), you can add the following configure.ac check:

AC_MSG_CHECKING([for espeak_TextToPhonemes])
AC_LANG_PUSH(C++)
AC_COMPILE_IFELSE(
    [AC_LANG_PROGRAM(
        [[#include "espeak/speak_lib.h"]],
        [[const char * (*ptr)(const void **, int, int);]
         [ptr = espeak_TextToPhonemes;]])
    ],[
        AC_MSG_RESULT([yes])
        AC_DEFINE(HAVE_ESPEAK_TEXTTOPHONEMES, [], [Does eSpeak have espeak_TextToPhonemes])
    ],[
        AC_MSG_RESULT([no])
    ])
AC_LANG_POP(C++)

This example uses espeak_TextToPhonemes as an example. You will need to change the ptr function pointer signature, the function name, the include and the HAVE_ define to match the function you are checking.

You can then use:

#if defined(HAVE_ESPEAK_TEXTTOPHONEMES)
    // Use espeak_TextToPhonemes
#endif

in your code.