threads / patch / 6866

patchNew autoconf test for iconv

Subject: [PATCH] New autoconf test for iconv

## tl;dr

One message between Feb 18, 2007 and Feb 18, 2007. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Fredrik Kuivinen· Feb 18, 2007, 08:44 UTC · lore

On a Solaris machine I have access to libc contains the symbol "iconv" but, when compiling with gcc and including iconv.h we get iconv.h from GNU libiconv. This header file define (among other things) "iconv" to "libiconv" and so on.

In order to link with GNU libiconv we need -liconv. Currently we test if the symbol "iconv" is in libc (which is true), then we get a undefined reference error because we don't have libiconv_open.

The solution this patch implements is to compile and link a small test program, instead of just checking if the libraries (libc and libiconv) contains the symbol "iconv".

Signed-off-by: Fredrik Kuivinen <frekui@gmail.com>
---
 configure.ac |   31 +++++++++++++++++++++++++------
 1 files changed, 25 insertions(+), 6 deletions(-)
Show changes to configure.ac +25 −6
diff --git a/configure.ac b/configure.ac
index 7cfb3a0..3a8e778 100644
--- a/configure.ac
+++ b/configure.ac
@@ -114,13 +114,32 @@ AC_CHECK_LIB([expat], [XML_ParserCreate],
 [NO_EXPAT=YesPlease])
 AC_SUBST(NO_EXPAT)
 #
-# Define NEEDS_LIBICONV if linking with libc is not enough (Darwin).
+# Define NEEDS_LIBICONV if linking with libc is not enough (Darwin and
+# some Solaris installations).
 # Define NO_ICONV if neither libc nor libiconv support iconv.
-AC_CHECK_LIB([c], [iconv],
-	[NEEDS_LIBICONV=],
-	AC_CHECK_LIB([iconv], [iconv],
-		[NEEDS_LIBICONV=YesPlease],
-		[NO_ICONV=YesPlease]))
+AC_DEFUN([ICONVTEST_SRC], [
+#include <iconv.h>
+
+int main(void)
+{
+	iconv_open("", "");
+	return 0;
+}
+])
+AC_MSG_CHECKING([for iconv in -lc])
+AC_LINK_IFELSE(ICONVTEST_SRC,
+	[AC_MSG_RESULT([yes])
+	NEEDS_LIBICONV=],
+	[AC_MSG_RESULT([no])
+	old_LIBS="$LIBS"
+	LIBS="$LIBS -liconv"
+	AC_MSG_CHECKING([for iconv in -liconv])
+	AC_LINK_IFELSE(ICONVTEST_SRC,
+		[AC_MSG_RESULT([yes])
+		NEEDS_LIBICONV=YesPlease],
+		[AC_MSG_RESULT([no])
+		NO_ICONV=YesPlease])
+	LIBS="$old_LIBS"])
 AC_SUBST(NEEDS_LIBICONV)
 AC_SUBST(NO_ICONV)
 test -n "$NEEDS_LIBICONV" && LIBS="$LIBS -liconv"

← back to recent threads