bug-autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: strdup falsely detected when CFLAGS contains -ansi on MSYS/MinGW (gc


From: Chris Pickett
Subject: Re: strdup falsely detected when CFLAGS contains -ansi on MSYS/MinGW (gcc)
Date: Sun, 28 Dec 2008 21:27:10 -0500
User-agent: Thunderbird 1.5.0.14 (Macintosh/20071210)

Chris Pickett wrote:
Hi,

When -ansi is passed to GCC, strdup becomes unavailable on MSYS/MinGW, but autoconf still detects the existence of strdup. The mingw string.h is in /mingw/include/string.h, and includes some funny stuff with #ifndef __STRICT_ANSI__ and later #ifndef _NO_OLDNAMES. The former gets defined by GCC with -ansi, the latter I couldn't see where it gets defined if at all.

Ok, I can do better than that.  string.h looks like this:

#ifndef __STRICT_ANSI__
...
_CRTIMP char* __cdecl __MINGW_NOTHROW _strdup (const char*) __MINGW_ATTRIB_MALLOC;
...
#ifndef _NO_OLDNAMES
...
_CRTIMP char* __cdecl __MINGW_NOTHROW strdup (const char*) __MINGW_ATTRIB_MALLOC;
...
#endif /* _NO_OLDNAMES */
#endif  /* Not __STRICT_ANSI__ */

So it seems like the configure test for strdup isn't using CFLAGS when it invokes the compiler but in this case it needs to so that __STRICT_ANSI__ is defined and strdup is unavailable.

Maybe there's a way to force this and I missed it?  Or should I just:

#undef __STRICT_ANSI__
#include <string.h>
#define __STRICT_ANSI__

Thanks,
Chris

Chris

mkdir src
cat >configure.ac <<\END
AC_INIT(a,1)
AM_INIT_AUTOMAKE(foreign)
AC_CONFIG_FILES(Makefile src/Makefile)
AC_PROG_CC
AC_PROG_LIBTOOL
AC_REPLACE_FUNCS([strdup])
AC_CONFIG_HEADERS([config.h])
AC_OUTPUT
END
cat >Makefile.am <<\END
SUBDIRS = src
END
cat >src/Makefile.am <<\END
libcheck_la_LIBADD = @LTLIBOBJS@
lib_LTLIBRARIES = libcheck.la
END
cat >src/libcheck.c <<\END
#if HAVE_CONFIG_H
#include "config.h"
#endif

#include <string.h>

#if !HAVE_STRDUP
char *strdup (const char *str);
#endif /* !HAVE_STRDUP */

void use_strdup (void)
{
  strdup (NULL);
}
END
cat >src/strdup.c <<\END
char *
strdup (const char *str)
{
  /* obviously this is broken */
  return NULL;
}
END

autoreconf -vif # all is fine, src/strdup.c is there

CFLAGS="-Wall -ansi" ./configure # says yes for strdup (incorrectly)

make # libcheck.c:13: warning: implicit declaration of function `strdup'

make clean

CFLAGS="-Wall" ./configure # says yes for strdup (correctly)

make # libcheck.c:13: warning: null argument where non-null required (arg 1)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]