[tlbuild] missing libiconv when compiling xdvik on FreeBSD

Mojca Miklavec mojca.miklavec.lists at gmail.com
Mon Apr 2 16:44:12 CEST 2018


On 21 September 2017 at 13:41, Mojca Miklavec wrote:
> On 16 September 2017 at 12:40, Mojca Miklavec wrote:
>> Hi,
>>
>> We just tried to compile TL on FreeBSD 11.1. It break when building
>> xdvik even though libiconv is present on the machine (but there's no
>> "-liconv" in the link command).
>>
>> Does anyone know the best way to proceed?
>>
>> libtool: link: cc -Wimplicit -Wreturn-type
>> -Wdeclaration-after-statement -Wno-unknown-pragmas -g -O2 -o xdvi-bin
>> main.o -Wl,--allow-multiple-definition  libxdvi.a
>> /path/to/Work/texk/kpathsea/.libs/libkpathsea.a
>> /path/to/Work/libs/freetype2/libfreetype.a -L/usr/local/lib -lXaw
>> -lXmu -lXt -lSM -lICE -lXext -lXpm -lX11 -lm
>> libxdvi.a(util.o): In function `iconv_convert_string':
>> /path/to/Work/texk/xdvik/../../../texk/xdvik/util.c:1829: undefined
>> reference to `libiconv_open'
>> /path/to/Work/texk/xdvik/../../../texk/xdvik/util.c:1846: undefined
>> reference to `libiconv'
>> /path/to/Work/texk/xdvik/../../../texk/xdvik/util.c:1857: undefined
>> reference to `libiconv_close'
>> /path/to/Work/texk/xdvik/../../../texk/xdvik/util.c:1852: undefined
>> reference to `libiconv_close'
>> libxdvi.a(encodings.o): In function `cjk2unicode':
>> /path/to/Work/texk/xdvik/../../../texk/xdvik/encodings.c:3059:
>> undefined reference to `libiconv'
>> /path/to/Work/texk/xdvik/../../../texk/xdvik/encodings.c:3044:
>> undefined reference to `libiconv_open'
>> libxdvi.a(encodings.o): In function `close_iconv':
>> /path/to/Work/texk/xdvik/../../../texk/xdvik/encodings.c:3021:
>> undefined reference to `libiconv_close'
>> cc: error: linker command failed with exit code 1 (use -v to see invocation)
>> gmake[5]: *** [Makefile:763: xdvi-bin] Error 1
>> gmake[5]: Leaving directory '/path/to/Work/texk/xdvik'
>> gmake[4]: *** [Makefile:996: all-recursive] Error 1
>> gmake[4]: Leaving directory '/path/to/Work/texk/xdvik'
>> gmake[3]: *** [Makefile:585: all] Error 2
>> gmake[3]: Leaving directory '/path/to/Work/texk/xdvik'
>> gmake[2]: *** [Makefile:906: recurse] Error 1
>> gmake[2]: Leaving directory '/path/to/Work/texk'
>> gmake[1]: *** [Makefile:486: all-recursive] Error 1
>> gmake[1]: Leaving directory '/path/to/Work/texk'
>> gmake: *** [Makefile:575: all-recursive] Error 1
>
> I believe that the problem lies in texk/xdvik/m4/xdvi-check-iconv.m4.
> The log from configuring xdvik says:
>
> checking for iconv.h... yes
> checking for library containing iconv... none required
> checking for iconv input type... char **
>
> There is this part of code that I don't entirely understand (or
> rather: didn't yet take enough time to decrypt it):
>
>
> AC_LANG_CONFTEST([AC_LANG_PROGRAM([[#include <stdlib.h>
> #include <iconv.h>]],
>                                   [[iconv_t cd = iconv_open("","");]])])
> xdvi_cv_search_iconv=no
> for xdvi_lib in "" -liconv -lrecode; do
>   LIBS="$xdvi_lib $xdvi_iconv_save_LIBS"
>   AC_LINK_IFELSE([],
>                  [xdvi_cv_search_iconv=$xdvi_lib
>                   break])
> done
> test "x$xdvi_cv_search_iconv" = x && xdvi_cv_search_iconv="none required"
> LDFLAGS=$xdvi_iconv_save_LDFLAGS
> LIBS=$xdvi_iconv_save_LIBS])
> ]) # _XDVI_ICONV_LIB
>
>
> but I suspect that the code is trying to compile with "-liconv" which
> succeeds and then somehow concludes
>     xdvi_cv_search_iconv="none required"
>
> and doesn't add any iconv flag like it should.
>
> What's the current upstream tracker for xdvi?

Here's a follow-up from
http://tug.org/pipermail/tlbuild/2018q2/004161.html

On 2 April 2018 at 14:45, Mojca Miklavec wrote:
>
> I figured out that ICU build errors seem to be ignored somehow.
>
> The command that eventually fails is the following:
>
> /bin/sh ./libtool  --tag=CC   --mode=link cc -Wimplicit -Wreturn-type
> -Wdeclaration-after-statement -Wno-unknown-pragmas -g -O2   -o
> xdvi-bin main.o libxdvi.a /path/to/Work/texk/kpathsea/libkpathsea.la
> /path/to/Work/libs/freetype2/libfreetype.a -L/usr/local/lib -Xlinker
> --allow-multiple-definition  -lXaw -lXmu -lXt -lSM -lICE -lXext -lXpm
> -lX11   -lm
> libtool: link: cc  -o xdvi-bin main.o -Wl,--allow-multiple-definition
> libxdvi.a /path/to/Work/texk/kpathsea/.libs/libkpathsea.a
> /path/to/Work/libs/freetype2/libfreetype.a -L/usr/local/lib -lXaw
> -lXmu -lXt -lSM -lICE -lXext -lXpm -lX11 -lm
> libxdvi.a(util.o): In function `iconv_convert_string':
> /path/to/Work/texk/xdvik/../../../texk/xdvik/util.c:1829: undefined
> reference to `libiconv_open'
> /path/to/Work/texk/xdvik/../../../texk/xdvik/util.c:1846: undefined
> reference to `libiconv'
> /path/to/Work/texk/xdvik/../../../texk/xdvik/util.c:1857: undefined
> reference to `libiconv_close'
> /path/to/Work/texk/xdvik/../../../texk/xdvik/util.c:1852: undefined
> reference to `libiconv_close'
> libxdvi.a(encodings.o): In function `cjk2unicode':
> /path/to/Work/texk/xdvik/../../../texk/xdvik/encodings.c:3059:
> undefined reference to `libiconv'
> /path/to/Work/texk/xdvik/../../../texk/xdvik/encodings.c:3044:
> undefined reference to `libiconv_open'
> libxdvi.a(encodings.o): In function `close_iconv':
> /path/to/Work/texk/xdvik/../../../texk/xdvik/encodings.c:3021:
> undefined reference to `libiconv_close'
> cc: error: linker command failed with exit code 1 (use -v to see invocation)
>
>
> I then figured out that if I explicitly add "-liconv" to
>
> cc -Wimplicit -Wreturn-type -Wdeclaration-after-statement
> -Wno-unknown-pragmas -g -O2 -o xdvi-bin main.o
> -Wl,--allow-multiple-definition  libxdvi.a
> /path/to/Work/texk/kpathsea/.libs/libkpathsea.a
> /path/to/Work/libs/freetype2/libfreetype.a -L/usr/local/lib -lXaw
> -lXmu -lXt -lSM -lICE -lXext -lXpm -lX11 -lm
>
> then the build succeeds and the build completes.
>
> Now, I tried to come up with a proper patch for this, but I'm super confused.
>
> The code to take care of the flags lives in
>     /texk/xdvik/m4/xdvi-check-iconv.m4
>
> It's this one in particular:
>
> # _XDVI_ICONV_LIB
> # ---------------
> # Check for library containing iconv(), could be -liconv or -lrecode.
> # Much like AC_SEARCH_LIBS([iconv], [iconv recode]),
> # but needs to '#include <iconv.h>'.
> m4_define([_XDVI_ICONV_LIB], [dnl
> AC_CACHE_CHECK([for library containing iconv],
>                [xdvi_cv_search_iconv], [dnl
> xdvi_iconv_save_LDFLAGS=$LDFLAGS
> xdvi_iconv_save_LIBS=$LIBS
> LDFLAGS="$iconv_libpath $LDFLAGS"
> AC_LANG_CONFTEST([AC_LANG_PROGRAM([[#include <stdlib.h>
> #include <iconv.h>]],
>                                   [[iconv_t cd = iconv_open("","");]])])
> xdvi_cv_search_iconv=no
> for xdvi_lib in "" -liconv -lrecode; do
>   LIBS="$xdvi_lib $xdvi_iconv_save_LIBS"
>   AC_LINK_IFELSE([],
>                  [xdvi_cv_search_iconv=$xdvi_lib
>                   break])
> done
> test "x$xdvi_cv_search_iconv" = x && xdvi_cv_search_iconv="none required"
> LDFLAGS=$xdvi_iconv_save_LDFLAGS
> LIBS=$xdvi_iconv_save_LIBS])
> ]) # _XDVI_ICONV_LIB
>
>
> The result is
>     configure:16097: checking for library containing iconv
>     configure:16120: cc -o conftest -g -O2 conftest.c -lm >&5
>     configure:16120: $? = 0
>     configure:16131: result: none required
>
> And in fact "cc test.c -o test" on
>
> $ cat test.c
> #include <stdlib.h>
> #include <iconv.h>
>
> int main()
> {
> iconv_t cd = iconv_open("", "");
> return 0;
> }
>
> succeeds without the need to supply -liconv, yet the command to
> compile xdvi doesn't work without -liconv.
>
> Full log is here for example (it's somewhat long):
> http://build.contextgarden.net/builders/texlive.freebsd-amd64.prg/builds/44/steps/shell/logs/stdio/text

With some help from the #freebsd IRC channel ...

This one might shed some light:
    https://lists.freebsd.org/pipermail/freebsd-ports/2013-August/085459.html

I realized that:

# this works
$ cc test.c -o test

# and this one doesn't
$ cc test.c -o test -I/usr/local/include
/tmp/test-ae5fb2.o: In function `main':
test.c:(.text+0x20): undefined reference to `libiconv_open'
cc: error: linker command failed with exit code 1 (use -v to see invocation)

# this one works again
cc test.c -o test -I/usr/local/include -L/usr/local/lib -liconv

This is because libiconv's iconv.h does:

    #define iconv_open libiconv_open
    ...
    #define iconv_close libiconv_close

Now, xdvi on checks the first one, realizes that one doesn't need to
add -liconv, but then another dependency needs -I/usr/local/include
and that breaks the build.

I was pointed to
    https://www.gnu.org/software/gettext/manual/html_node/AM_005fICONV.html
which is considered an "upstream" version that is supposed to take
care of all these strange iconv anomalies.

So I took an upstream copy of iconv.m4, put it to
texk/xdvik/m4/iconv.m4 and made the following change:

--- texk/xdvik/configure.ac (revision 47244)
+++ texk/xdvik/configure.ac (working copy)
@@ -114,7 +114,7 @@
 AC_CHECK_HEADERS([netdb.h sys/bsdtypes.h sys/param.h unistd.h
sys/fcntl.h regex.h])

 # Checks for iconv
-XDVI_CHECK_ICONV
+AM_ICONV

 # Checks for langinfo
 XDVI_CHECK_LANGINFO

I was then stuck because apparently I didn't run all the autofoo magic
correctly.

automake
configure.ac:117: error: required file '../../build-aux/config.rpath' not found

and then I ended up with

cc -DHAVE_CONFIG_H -I. -I../../../texk/xdvik
-I../../../texk/xdvik/gui -DPS_GS
-I/home/context/texlive/Build/source/Work/texk
-I/home/context/texlive/Build/source/texk
-I/home/context/texlive/Build/source/Work/libs/freetype2/freetype2
-I/usr/local/include @iconv_includes@  -Wimplicit -Wreturn-type
-Wdeclaration-after-statement -Wno-unknown-pragmas -g -O2 -MT
browser.o -MD -MP -MF $depbase.Tpo -c -o browser.o
../../../texk/xdvik/browser.c &&\
mv -f $depbase.Tpo $depbase.Po
cc: error: no such file or directory: '@iconv_includes@'

Could someone please test if the above one-line patch followed by the
correct reconfigure works on other platforms? That should be the
correct thing to do in any case, but I hope it would eventually solve
the problem for FreeBSD as well.

Mojca


More information about the tlbuild mailing list