From owner-freebsd-questions@freebsd.org Tue Jul 14 18:04:59 2015 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 034B29A125D for ; Tue, 14 Jul 2015 18:04:59 +0000 (UTC) (envelope-from tijl@freebsd.org) Received: from mailrelay118.isp.belgacom.be (mailrelay118.isp.belgacom.be [195.238.20.145]) by mx1.freebsd.org (Postfix) with ESMTP id 8F76FFD3 for ; Tue, 14 Jul 2015 18:04:58 +0000 (UTC) (envelope-from tijl@freebsd.org) X-Belgacom-Dynamic: yes X-Cloudmark-SP-Filtered: true X-Cloudmark-SP-Result: v=1.1 cv=yz6z4UlqfYe1Iv9USMliYggvHmbgQ4ACOrhY3D/q6Wc= c=1 sm=2 a=IoZrpO97AAAA:8 a=FuVK2u3hnbUzN0jQfmcA:9 a=CjuIK1q_8ugA:10 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2CUBgA3TqVV/++YsFtbgxOBPcNIAoFLPBEBAQEBAQEBgQqEJAEBBDocIxALDgoJJQ8qHgYTiDIBzzsBAQEBAQUBAQEBHotMhQYHhCsBBJQyjAWBQYQYkxYmggwcgVU8MYJLAQEB Received: from 239.152-176-91.adsl-dyn.isp.belgacom.be (HELO kalimero.tijl.coosemans.org) ([91.176.152.239]) by relay.skynet.be with ESMTP; 14 Jul 2015 20:03:49 +0200 Received: from kalimero.tijl.coosemans.org (kalimero.tijl.coosemans.org [127.0.0.1]) by kalimero.tijl.coosemans.org (8.15.2/8.15.2) with ESMTP id t6EI3kp6004875; Tue, 14 Jul 2015 20:03:47 +0200 (CEST) (envelope-from tijl@FreeBSD.org) Date: Tue, 14 Jul 2015 20:03:45 +0200 From: Tijl Coosemans To: Dennis Glatting 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> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Jul 2015 18:04:59 -0000 On Tue, 14 Jul 2015 09:40:29 -0700 Dennis Glatting 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 > #include > > 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.