Problem (with solution) in AC_CHECK_FUNCS

Suppose we have something like
AC_CHECK_FUNCS([setitimer], [], AC_MSG_ERROR([...]))
then autoconf (version 2.54c and previous ones) tries to compile a program containing (inessential lines snipped)
#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 setitimer (); char (*f) ();
int main () { /* The GNU C library defines this for functions which it implements to always fail with ENOSYS. Some functions are actually named something starting with __ and the normal name is an alias. */ #if defined (__stub_setitimer) || defined (__stub___setitimer) choke me #else f = setitimer; #endif
The problem is with the assignment `f = setitimer;' in case we are using a standard conforming (strictly speaking) C++ compiler. In fact, in standard C++, a value of type "char (*)() C" (a C function) cannot be assigned to an entity of type "char (*)()" (a C++ function).
The fix is easy: it suffices to change autoconf so that, instead of generating
------------------------------------------------------------------ #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 setitimer (); char (*f) (); ------------------------------------------------------------------
it produces
------------------------------------------------------------------ #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 setitimer (); char (*f) (); #ifdef __cplusplus } #endif ------------------------------------------------------------------
so that, in C++, both `f' and `setitimer' have C linkage. All the best
Roberto

Thanks, I'm installing this:
Index: ChangeLog from Akim Demaille akim@epita.fr
* lib/autoconf/c.m4 (AC_LANG_FUNC_LINK_TRY): Wrap the `f' declaration in extern "C" too. Reported by Roberto Bagnara.
Index: THANKS =================================================================== RCS file: /cvsroot/autoconf/autoconf/THANKS,v retrieving revision 1.100 diff -u -u -r1.100 THANKS --- THANKS 28 Oct 2002 07:15:06 -0000 1.100 +++ THANKS 6 Nov 2002 12:08:18 -0000 @@ -156,6 +156,7 @@ Richard Stallman rms@gnu.org Robert Lipe robertlipe@usa.net Robert S. Maier rsm@math.arizona.edu +Roberto Bagnara bagnara@cs.unipr.it Roland McGrath roland@gnu.org RĂ¼diger Kuhlmann info@ruediger-kuhlmann.de Ruediger Kuhlmann uck4@rz.uni-karlsruhe.de Index: lib/autoconf/c.m4 =================================================================== RCS file: /cvsroot/autoconf/autoconf/lib/autoconf/c.m4,v retrieving revision 1.170 diff -u -u -r1.170 c.m4 --- lib/autoconf/c.m4 31 Oct 2002 08:27:15 -0000 1.170 +++ lib/autoconf/c.m4 6 Nov 2002 12:08:19 -0000 @@ -173,11 +173,15 @@ /* 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 $1 (); char (*f) (); +#ifdef __cplusplus +} +#endif ], [/* The GNU C library defines this for functions which it implements to always fail with ENOSYS. Some functions are actually named
participants (2)
-
Akim Demaille
-
Roberto Bagnara