Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 14 Jul 2015 20:03:45 +0200
From:      Tijl Coosemans <tijl@FreeBSD.org>
To:        Dennis Glatting <freebsd@pki2.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: What's the magic of linking against iconv (clang/gcc5)?
Message-ID:  <20150714200345.04354c5b@kalimero.tijl.coosemans.org>
In-Reply-To: <1436892029.68808.8.camel@pki2.com>
References:  <1436892029.68808.8.camel@pki2.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 14 Jul 2015 09:40:29 -0700 Dennis Glatting <freebsd@pki2.com> wrote:
> My system:
> 
> root@Tasha# uname -a
> FreeBSD Tasha 10.2-BETA1 FreeBSD 10.2-BETA1 #0 r285434: Sun Jul 12
> 16:57:18 PDT 2015
> root@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@Tasha# cc foo.c
> root@Tasha# 
> 
> However, if I compiler with gcc5:
> 
> root@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@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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20150714200345.04354c5b>