Skip to content

Commit e63ccb8

Browse files
frekuiJunio C Hamano
authored andcommitted
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>
1 parent 437b1b2 commit e63ccb8

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

configure.ac

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,32 @@ AC_CHECK_LIB([expat], [XML_ParserCreate],
114114
[NO_EXPAT=YesPlease])
115115
AC_SUBST(NO_EXPAT)
116116
#
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).
118119
# 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"])
124143
AC_SUBST(NEEDS_LIBICONV)
125144
AC_SUBST(NO_ICONV)
126145
test -n "$NEEDS_LIBICONV" && LIBS="$LIBS -liconv"

0 commit comments

Comments
 (0)