Hi Bruno,
On Sat, 4 Jan 2020, Bruno Haible wrote:
Hi Martin,
Thank you for the careful analysis.
The root cause for this issue seems to be that clang has a builtin for the
strndup function, even if the target platform actually doesn't have it.
This manifests itself during configure like this:
configure:31903: checking whether strndup is declared
configure:31903: x86_64-w64-mingw32-gcc -c -g -O2 conftest.c >&5
conftest.c:267:10: warning: implicitly declaring library function
'strndup' with type 'char *(const char *, unsigned long long)'
[-Wimplicit-function-declaration]
(void) strndup;
^
conftest.c:267:10: note: include the header <string.h> or explicitly
provide a declaration for 'strndup'
1 warning generated.
configure:31903: $? = 0
configure:31903: result: yes
This results in variables set up like this:
ac_cv_func_strndup=no
This is correct and expected: mingw does not have strndup.
ac_cv_have_decl_strndup=yes
This is wrong: it should be ac_cv_have_decl_strndup=no.
GNULIB_STRNDUP = 1
HAVE_DECL_STRNDUP = 1
REPLACE_STRNDUP = 0
Which then leads to the errors quoted above.
There are two possible ways to fix this issue:
* Modify AC_CHECK_DECL to disable the clang built-in declarations
for strndup and many other functions.
* Ignore the result of AC_CHECK_DECL when the compiler is clang,
and use the AC_CHECK_FUNC result instead.
The second option is work in many places, in particular because in some
cases the AC_CHECK_FUNC needs to know which libraries to add to LIBS
for the test. I therefore prefer the first one.
With this patch, the configure output should be:
checking whether the compiler is clang... yes
checking for compiler option needed when checking for declarations...
-Werror=implicit-function-declaration
checking whether strndup is declared... no
Awesome, this patch makes a lot of sense to me, and seems to work fine.
Thanks!
// Martin