From 91b00c5605955ec8167fbbedd5dfe7d722ac9639 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sun, 16 Feb 2020 14:25:06 +0100 Subject: [PATCH] configure.ac: test for iconv_open with #include MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previously used AC_SEARCH_LIBS uses AC_LANG_CALL, which is discouraged because it intentionally violates the C type system: it has no way of specifying function parameters, so it does not include the required headers to suppress type warnings: https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/html_node/Generating-Sources.html The new code does what AC_SEARCH_LIBS does, but uses AC_LANG_PROGRAM instead of AC_LANG_CALL. It explicitly includes iconv.h and calls iconv_open with the correct number and type of arguments. This fixes compilation on systems where libiconv’s iconv.h is discovered first, but glibc also provides iconv. Previously, this would result in configure discovering glibc’s iconv, and make failing to compile because -liconv wasn’t specified, but iconv.h pulled in libiconv. --- configure.ac | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 0b99cf803..3ab6345ec 100644 --- a/configure.ac +++ b/configure.ac @@ -84,8 +84,11 @@ AC_SEARCH_LIBS([ev_run], [ev], , [AC_MSG_FAILURE([cannot find the required ev_ru AC_SEARCH_LIBS([shm_open], [rt], [], [], [-pthread]) -AC_SEARCH_LIBS([iconv_open], [iconv], , -AC_SEARCH_LIBS([libiconv_open], [iconv], , [AC_MSG_FAILURE([cannot find the required iconv_open() function despite trying to link with -liconv])])) +AC_LINK_IFELSE([AC_LANG_PROGRAM([#include ], [iconv_open(0, 0)])], , + [LIBS="-liconv $LIBS" + AC_LINK_IFELSE([AC_LANG_PROGRAM([#include ], [iconv_open(0, 0)])], , + [AC_MSG_FAILURE([cannot find the required iconv_open() function despite trying to link with -liconv])])] +) AX_PTHREAD