What's the magic of linking against iconv (clang/gcc5)?

Tijl Coosemans tijl at FreeBSD.org
Tue Jul 14 18:04:59 UTC 2015


On Tue, 14 Jul 2015 09:40:29 -0700 Dennis Glatting <freebsd at pki2.com> wrote:
> My system:
> 
> root at Tasha# uname -a
> FreeBSD Tasha 10.2-BETA1 FreeBSD 10.2-BETA1 #0 r285434: Sun Jul 12
> 16:57:18 PDT 2015
> root at Tasha:/disk-2/obj/disk-1/src/sys/SMUNI-FreeBSD10-amd64  amd64
> 
> 
> I have a very simple program:
> 
> #include <iconv.h>
> #include <stdio.h>
> 
> int
> main( void ) {
> 
>   iconv_t fd = 0;
> 
>   iconv_close( fd );
> 
>   return 0;
> }
> 
> 
> If I compile with clang, I have no trouble:
> 
> root at Tasha# cc foo.c
> root at Tasha# 
> 
> However, if I compiler with gcc5:
> 
> root at Tasha# gcc5 foo.c
> /tmp//ccDHDghd.o: In function `main':
> foo.c:(.text+0x18): undefined reference to `libiconv_close'
> collect2: error: ld returned 1 exit status
> 
> According to iconv(3), I should link against c yet I get the same error:
> 
> root at Tasha# gcc5 foo.c -lc
> /tmp//ccsKwlf3.o: In function `main':
> foo.c:(.text+0x18): undefined reference to `libiconv_close'
> collect2: error: ld returned 1 exit status
> 
> I'm confused why this doesn't work and have searched through the system
> libraries. (I have verbose output below). I /only/ have a problem with
> iconv. There is some difference between these compilers that I do not
> understand. 
> 
> Clue please.

The lang/gcc* ports always compile with -I/usr/local/include, so they
end up including /usr/local/include/iconv.h which belongs to libiconv
while clang includes /usr/include/iconv.h.  So with gcc you either
have to link with -liconv or compile with -DLIBICONV_PLUG which makes
/usr/local/include/iconv.h behave like /usr/include/iconv.h.


More information about the freebsd-questions mailing list