{"thread":{"id":"6866","subject":"[PATCH] New autoconf test for iconv","startedAt":"2007-02-18T08:44:42Z","lastAt":"2007-02-18T08:44:42Z","messageCount":1,"participants":["Fredrik Kuivinen"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"34946","messageId":"20070218084442.6418.73657.stgit@c165","threadId":"6866","inReplyTo":null,"subject":"[PATCH] New autoconf test for iconv","fromName":"Fredrik Kuivinen","fromEmail":"frekui@gmail.com","sentAt":"2007-02-18T08:44:42Z","receivedAt":"2007-02-18T08:44:42Z","isPatch":true,"sender":{"key":"frekui@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13770967?v=4"},"body":"\nOn a Solaris machine I have access to libc contains the symbol\n\"iconv\" but, when compiling with gcc and including iconv.h we get\niconv.h from GNU libiconv. This header file define (among other\nthings) \"iconv\" to \"libiconv\" and so on. \n\nIn order to link with GNU libiconv we need -liconv. Currently we\ntest if the symbol \"iconv\" is in libc (which is true), then we get\na undefined reference error because we don't have libiconv_open.\n\nThe solution this patch implements is to compile and link a\nsmall test program, instead of just checking if the libraries\n(libc and libiconv) contains the symbol \"iconv\".\n\nSigned-off-by: Fredrik Kuivinen <frekui@gmail.com>\n\n---\n\n configure.ac |   31 +++++++++++++++++++++++++------\n 1 files changed, 25 insertions(+), 6 deletions(-)\n\ndiff --git a/configure.ac b/configure.ac\nindex 7cfb3a0..3a8e778 100644\n--- a/configure.ac\n+++ b/configure.ac\n@@ -114,13 +114,32 @@ AC_CHECK_LIB([expat], [XML_ParserCreate],\n [NO_EXPAT=YesPlease])\n AC_SUBST(NO_EXPAT)\n #\n-# Define NEEDS_LIBICONV if linking with libc is not enough (Darwin).\n+# Define NEEDS_LIBICONV if linking with libc is not enough (Darwin and\n+# some Solaris installations).\n # Define NO_ICONV if neither libc nor libiconv support iconv.\n-AC_CHECK_LIB([c], [iconv],\n-\t[NEEDS_LIBICONV=],\n-\tAC_CHECK_LIB([iconv], [iconv],\n-\t\t[NEEDS_LIBICONV=YesPlease],\n-\t\t[NO_ICONV=YesPlease]))\n+AC_DEFUN([ICONVTEST_SRC], [\n+#include <iconv.h>\n+\n+int main(void)\n+{\n+\ticonv_open(\"\", \"\");\n+\treturn 0;\n+}\n+])\n+AC_MSG_CHECKING([for iconv in -lc])\n+AC_LINK_IFELSE(ICONVTEST_SRC,\n+\t[AC_MSG_RESULT([yes])\n+\tNEEDS_LIBICONV=],\n+\t[AC_MSG_RESULT([no])\n+\told_LIBS=\"$LIBS\"\n+\tLIBS=\"$LIBS -liconv\"\n+\tAC_MSG_CHECKING([for iconv in -liconv])\n+\tAC_LINK_IFELSE(ICONVTEST_SRC,\n+\t\t[AC_MSG_RESULT([yes])\n+\t\tNEEDS_LIBICONV=YesPlease],\n+\t\t[AC_MSG_RESULT([no])\n+\t\tNO_ICONV=YesPlease])\n+\tLIBS=\"$old_LIBS\"])\n AC_SUBST(NEEDS_LIBICONV)\n AC_SUBST(NO_ICONV)\n test -n \"$NEEDS_LIBICONV\" && LIBS=\"$LIBS -liconv\"\n"}]}