New autoconf test for iconv
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> Signed-off-by: Junio C Hamano <junkio@cox.net>
Fredrik Kuivinen committed
Feb 18, 2007 at 09:44 UTC
e63ccb84e3e29d428548669a7a1206d386a57d6d
1 file changed
+25
-6
configure.ac
+25
-6
@@ -114,13 +114,32 @@ AC_CHECK_LIB([expat], [XML_ParserCreate],
114
[NO_EXPAT=YesPlease])
115
AC_SUBST(NO_EXPAT)
116
#
117
-# Define NEEDS_LIBICONV if linking with libc is not enough (Darwin).
117
+# Define NEEDS_LIBICONV if linking with libc is not enough (Darwin and
118
+# some Solaris installations).
119
# Define NO_ICONV if neither libc nor libiconv support iconv.
119
-AC_CHECK_LIB([c], [iconv],
120
- [NEEDS_LIBICONV=],
121
- AC_CHECK_LIB([iconv], [iconv],
122
- [NEEDS_LIBICONV=YesPlease],
123
- [NO_ICONV=YesPlease]))
120
+AC_DEFUN([ICONVTEST_SRC], [
121
+#include <iconv.h>
122
+
123
+int main(void)
124
+{
125
+ iconv_open("", "");
126
+ return 0;
127
+}
128
+])
129
+AC_MSG_CHECKING([for iconv in -lc])
130
+AC_LINK_IFELSE(ICONVTEST_SRC,
131
+ [AC_MSG_RESULT([yes])
132
+ NEEDS_LIBICONV=],
133
+ [AC_MSG_RESULT([no])
134
+ old_LIBS="$LIBS"
135
+ LIBS="$LIBS -liconv"
136
+ AC_MSG_CHECKING([for iconv in -liconv])
137
+ AC_LINK_IFELSE(ICONVTEST_SRC,
138
+ [AC_MSG_RESULT([yes])
139
+ NEEDS_LIBICONV=YesPlease],
140
+ [AC_MSG_RESULT([no])
141
+ NO_ICONV=YesPlease])
142
+ LIBS="$old_LIBS"])
143
AC_SUBST(NEEDS_LIBICONV)
144
AC_SUBST(NO_ICONV)
145
test -n "$NEEDS_LIBICONV" && LIBS="$LIBS -liconv"