Date: Tue, 14 Jul 2015 09:40:29 -0700 From: Dennis Glatting <freebsd@pki2.com> To: freebsd-questions@freebsd.org Subject: What's the magic of linking against iconv (clang/gcc5)? Message-ID: <1436892029.68808.8.camel@pki2.com>
next in thread | raw e-mail | index | archive | help
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. (BTW, I'm compiling GNURadio 3.7.8git. There are two patches and everything compiles except where iconv is referenced.) root@Tasha# cc -v foo.c FreeBSD clang version 3.4.1 (tags/RELEASE_34/dot1-final 208032) 20140512 Target: x86_64-unknown-freebsd10.2 Thread model: posix Selected GCC installation: "/usr/bin/cc" -cc1 -triple x86_64-unknown-freebsd10.2 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name foo.c -mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -v -resource-dir /usr/bin/../lib/clang/3.4.1 -fdebug-compilation-dir /lib -ferror-limit 19 -fmessage-length 80 -mstackrealign -fobjc-runtime=gnustep -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o /tmp/foo-2bbf11.o -x c foo.c clang -cc1 version 3.4.1 based upon LLVM 3.4.1 default target x86_64-unknown-freebsd10.2 ignoring nonexistent directory "/usr/bin/../lib/clang/3.4.1/include" #include "..." search starts here: #include <...> search starts here: /usr/include/clang/3.4.1 /usr/include End of search list. "/usr/bin/ld" --eh-frame-hdr -dynamic-linker /libexec/ld-elf.so.1 --hash-style=both --enable-new-dtags -o a.out /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib /tmp/foo-2bbf11.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtend.o /usr/lib/crtn.o root@Tasha# gcc5 -v foo.c -lc Using built-in specs. COLLECT_GCC=gcc5 COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc5/gcc/x86_64-portbld-freebsd10.2/5.1.0/lto-wrapper Target: x86_64-portbld-freebsd10.2 Configured with: ./../gcc-5.1.0/configure --with-build-config=bootstrap-debug --disable-nls --enable-gnu-indirect-function --libdir=/usr/local/lib/gcc5 --libexecdir=/usr/local/libexec/gcc5 --program-suffix=5 --with-as=/usr/local/bin/as --with-gmp=/usr/local --with-gxx-include-dir=/usr/local/lib/gcc5/include/c++/ --with-ld=/usr/local/bin/ld --with-pkgversion='FreeBSD Ports Collection' --with-system-zlib --with-ecj-jar=/usr/local/share/java/ecj-4.5.jar --enable-languages=c,c++,objc,fortran,java --prefix=/usr/local --localstatedir=/var --mandir=/usr/local/man --infodir=/usr/local/info/gcc5 --build=x86_64-portbld-freebsd10.2 Thread model: posix gcc version 5.1.0 (FreeBSD Ports Collection) COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64' /usr/local/libexec/gcc5/gcc/x86_64-portbld-freebsd10.2/5.1.0/cc1 -quiet -v foo.c -quiet -dumpbase foo.c -mtune=generic -march=x86-64 -auxbase foo -version -o /tmp//ccIJPCLY.s GNU C11 (FreeBSD Ports Collection) version 5.1.0 (x86_64-portbld-freebsd10.2) compiled by GNU C version 5.1.0, GMP version 5.1.3, MPFR version 3.1.2, MPC version 1.0.3 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring nonexistent directory "/usr/local/lib/gcc5/gcc/x86_64-portbld-freebsd10.2/5.1.0/../../../../../x86_64-portbld-freebsd10.2/include" #include "..." search starts here: #include <...> search starts here: /usr/local/lib/gcc5/gcc/x86_64-portbld-freebsd10.2/5.1.0/include /usr/local/include /usr/local/lib/gcc5/gcc/x86_64-portbld-freebsd10.2/5.1.0/include-fixed /usr/include End of search list. GNU C11 (FreeBSD Ports Collection) version 5.1.0 (x86_64-portbld-freebsd10.2) compiled by GNU C version 5.1.0, GMP version 5.1.3, MPFR version 3.1.2, MPC version 1.0.3 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: d704dda7d1acf1756f63bafb76e30605 COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64' /usr/local/bin/as -v -o /tmp//cc2Z6z3x.o /tmp//ccIJPCLY.s GNU assembler version 2.25 (x86_64-portbld-freebsd10.2) using BFD version (GNU Binutils) 2.25 COMPILER_PATH=/usr/local/libexec/gcc5/gcc/x86_64-portbld-freebsd10.2/5.1.0/:/usr/local/libexec/gcc5/gcc/x86_64-portbld-freebsd10.2/5.1.0/:/usr/local/libexec/gcc5/gcc/x86_64-portbld-freebsd10.2/:/usr/local/lib/gcc5/gcc/x86_64-portbld-freebsd10.2/5.1.0/:/usr/local/lib/gcc5/gcc/x86_64-portbld-freebsd10.2/:/usr/local/lib/gcc5/gcc/x86_64-portbld-freebsd10.2/5.1.0/../../../../../x86_64-portbld-freebsd10.2/bin/ LIBRARY_PATH=/usr/local/lib/gcc5/gcc/x86_64-portbld-freebsd10.2/5.1.0/:/usr/local/lib/gcc5/gcc/x86_64-portbld-freebsd10.2/5.1.0/../../../../../x86_64-portbld-freebsd10.2/lib/:/usr/local/lib/gcc5/gcc/x86_64-portbld-freebsd10.2/5.1.0/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64' /usr/local/libexec/gcc5/gcc/x86_64-portbld-freebsd10.2/5.1.0/collect2 -plugin /usr/local/libexec/gcc5/gcc/x86_64-portbld-freebsd10.2/5.1.0/liblto_plugin.so -plugin-opt=/usr/local/libexec/gcc5/gcc/x86_64-portbld-freebsd10.2/5.1.0/lto-wrapper -plugin-opt=-fresolution=/tmp//ccMod0QF.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --eh-frame-hdr -V -dynamic-linker /libexec/ld-elf.so.1 /usr/lib/crt1.o /usr/lib/crti.o /usr/local/lib/gcc5/gcc/x86_64-portbld-freebsd10.2/5.1.0/crtbegin.o -L/usr/local/lib/gcc5/gcc/x86_64-portbld-freebsd10.2/5.1.0 -L/usr/local/lib/gcc5/gcc/x86_64-portbld-freebsd10.2/5.1.0/../../../../../x86_64-portbld-freebsd10.2/lib -L/usr/local/lib/gcc5/gcc/x86_64-portbld-freebsd10.2/5.1.0/../../.. /tmp//cc2Z6z3x.o -lc -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/local/lib/gcc5/gcc/x86_64-portbld-freebsd10.2/5.1.0/crtend.o /usr/lib/crtn.o GNU ld (GNU Binutils) 2.25 Supported emulations: elf_x86_64_fbsd elf_i386_fbsd elf_x86_64 elf_i386 elf_l1om elf_l1om_fbsd elf_k1om elf_k1om_fbsd /tmp//cc2Z6z3x.o: In function `main': foo.c:(.text+0x18): undefined reference to `libiconv_close' collect2: error: ld returned 1 exit status
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1436892029.68808.8.camel>