This problem was reported a couple of times in the gcc-help mailing list, but was not answered (I browsed the email archives). See e.g.: http://gcc.gnu.org/ml/libstdc++/2002-12/msg00129.html I saw the problem first in gcc-3.2 and it is everywhere up to gcc-3.3. I could not test 3.3.1 yet. The problem is NOT in 2.96 and NOT in 3.1.1. In a nutshell, I am trying to build *.so libs from C++ code, that include a static copy of libstdc++ for self-containment reasons. Example: Consider this file: hsw.cpp #include <iostream> void smw() { std::cout << "Hello, static world!\n"; } $ g++ -print-file-name=libstdc++.a /opt/TWWfsw/gcc33/lib/gcc-lib/i686-pc-linux-gnu/3.3/../../../libstdc++.a $ ls -la /opt/TWWfsw/gcc33/lib/gcc-lib/i686-pc-linux- gnu/3.3/../../../libstdc++.a -rw-r--r-- 1 cei cei 7897890 May 31 02:06 /opt/TWWfsw/gcc33/lib/gcc-lib/i686-pc-linux-gnu/3.3/../../../libstdc++.a $ g++ -save-temps -v -shared -o hsw.so hsw.cpp /opt/TWWfsw/gcc33/lib/gcc- lib/i686-pc-linux-gnu/3.3/../../../libstdc++.a Reading specs from /opt/TWWfsw/gcc33/lib/gcc-lib/i686-pc-linux-gnu/3.3/specs Configured with: /opt/build/gcc-3.3/configure --with-included-gettext --enable- libgcj --enable-__cxa_atexit --with-gnu-as --with-as=/opt/TWWfsw/gcc33/i686-pc- linux-gnu/bin/as --with-gnu-ld --with-ld=/opt/TWWfsw/gcc33/i686-pc-linux- gnu/bin/ld --datadir=/opt/TWWfsw/gcc33/share --with-local- prefix=/opt/TWWfsw/gcc33 --prefix=/opt/TWWfsw/gcc33 Thread model: posix gcc version 3.3 (TWW) /opt/TWWfsw/gcc33/lib/gcc-lib/i686-pc-linux-gnu/3.3/cc1plus -E -D__GNUG__=3 - quiet -v -D__GNUC__=3 -D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=0 -D_GNU_SOURCE hsw.cpp hsw.ii ignoring nonexistent directory "/opt/TWWfsw/gcc33/i686-pc-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /opt/TWWfsw/gcc33/include/c++/3.3 /opt/TWWfsw/gcc33/include/c++/3.3/i686-pc-linux-gnu /opt/TWWfsw/gcc33/include/c++/3.3/backward /opt/TWWfsw/gcc33/include /opt/TWWfsw/gcc33/lib/gcc-lib/i686-pc-linux-gnu/3.3/include /usr/include End of search list. /opt/TWWfsw/gcc33/lib/gcc-lib/i686-pc-linux-gnu/3.3/cc1plus -fpreprocessed hsw.ii -quiet -dumpbase hsw.cpp -auxbase hsw -version -o hsw.s GNU C++ version 3.3 (TWW) (i686-pc-linux-gnu) compiled by GNU C version 3.3 (TWW). GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 /opt/TWWfsw/gcc33/i686-pc-linux-gnu/bin/as -V -Qy -o hsw.o hsw.s GNU assembler version 2.12.1 (i686-pc-linux-gnu) using BFD version 2.12.1 /opt/TWWfsw/gcc33/lib/gcc-lib/i686-pc-linux-gnu/3.3/collect2 --eh-frame-hdr -m elf_i386 -shared -o hsw.so /usr/lib/crti.o /opt/TWWfsw/gcc33/lib/gcc-lib/i686- pc-linux-gnu/3.3/crtbeginS.o -L/usr/local/bin -L/opt/TWWfsw/gcc33/lib/gcc- lib/i686-pc-linux-gnu/3.3 -L/opt/TWWfsw/gcc33/lib/gcc-lib/i686-pc-linux- gnu/3.3/../../../../i686-pc-linux-gnu/lib -L/opt/TWWfsw/gcc33/lib/gcc-lib/i686- pc-linux-gnu/3.3/../../.. hsw.o /opt/TWWfsw/gcc33/lib/gcc-lib/i686-pc-linux- gnu/3.3/../../../libstdc++.a -lstdc++ -lm -rpath /opt/TWWfsw/gcc33r/lib - lgcc_s -lc -lgcc_s /opt/TWWfsw/gcc33/lib/gcc-lib/i686-pc-linux- gnu/3.3/crtendS.o /usr/lib/crtn.o /opt/TWWfsw/gcc33/i686-pc-linux-gnu/bin/ld: hsw.so: undefined versioned symbol name std::time_put_w@@GLIBCPP_3.2 /opt/TWWfsw/gcc33/i686-pc-linux-gnu/bin/ld: failed to set dynamic section sizes: Bad value collect2: ld returned 1 exit status
Created attachment 4927 [details] The gzipped hsw.ii temp file
This has been answered before, you have to bootstrap with --with-pic.
Ok, now I had more time to look into this. We got gcc-3.2.3, and compiled the libstdc++ with --with-pic. Now the issue looks slightly different: On Sparc/Solaris-7, there is no problem at all (sparc-sun-solaris2.7). But on Linux (i686-pc-linux-gnu) the problem remains: I keep getting the error: /opt/gcc_3.2.3/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/../../../../i686-pc-linux- gnu/bin/ld: ../blib/arch/auto/Verilog/Preproc/Preproc.so: undefined versioned symbol name std::time_put_w@@GLIBCPP_3.2 /opt/gcc_3.2.3/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/../../../../i686-pc-linux- gnu/bin/ld: failed to set dynamic section sizes: Bad value collect2: ld returned 1 exit status Few observations I made, hope that this helps: $ nm /opt/gcc_3.2.3/lib/libstdc++.so | grep time_put_w 000ae294 b _ZN9__gnu_cxx10time_put_wE 000ae294 B _ZSt10time_put_w@@GLIBCPP_3.2 $ nm /opt/gcc_3.2.3/lib/libstdc++.a | grep time_put_w 000004b4 B _ZN9__gnu_cxx10time_put_wE 000004b4 B _ZSt10time_put_w@@GLIBCPP_3.2 U _ZN9__gnu_cxx10time_put_wE On Solaris, there is no symbol containing "time_put_w" at all, and there are no symbols with GLIBCPP_3.2 either. Is there any option which has to be set? Please let me know if you need any further information/files/...
Delete (or move) the shared library and try again?
Subject: RE: link problems with static libstdc++ > Delete (or move) the shared library and try again? I already made sure that the libstdc++.so is not used. But here is what I did: $ pushd /opt/gcc_3.2.3/lib $ mkdir .dis $ mv libstdc++.so* libstdc++.la .dis $ popd $ g++ -save-temps -v -shared -o hsw.so hsw.cpp -lstdc++ Reading specs from /opt/gcc_3.2.3/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/specs Configured with: ./configure --prefix=/opt/gcc_3.2.3 --enable-shared --enable-threads=posix --enable-languages=c,c++,f77 Thread model: posix gcc version 3.2.3 /opt/gcc_3.2.3/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/cpp0 -lang-c++ -D__GNUG__=3 -D__DEPRECATED -D__EXCEPTIONS -v -D__GNUC__=3 -D__GNUC_MINOR__=2 -D__GNUC_PATCHLEVEL__=3 -D__GXX_ABI_VERSION=102 -D__ELF__ -Dunix -D__gnu_linux__ -Dlinux -D__ELF__ -D__unix__ -D__gnu_linux__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__NO_INLINE__ -D__STDC_HOSTED__=1 -D_GNU_SOURCE -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i686__ -D__tune_pentiumpro__ hsw.cpp hsw.ii GNU CPP version 3.2.3 (cpplib) (i386 Linux/ELF) ignoring nonexistent directory "/opt/gcc_3.2.3/i686-pc-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /opt/gcc_3.2.3/include/c++/3.2.3 /opt/gcc_3.2.3/include/c++/3.2.3/i686-pc-linux-gnu /opt/gcc_3.2.3/include/c++/3.2.3/backward /usr/local/include /opt/gcc_3.2.3/include /opt/gcc_3.2.3/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/include /usr/include End of search list. /opt/gcc_3.2.3/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/cc1plus -fpreprocessed hsw.ii -quiet -dumpbase hsw.cpp -version -o hsw.s GNU CPP version 3.2.3 (cpplib) (i386 Linux/ELF) GNU C++ version 3.2.3 (i686-pc-linux-gnu) compiled by GNU C version 3.1.1. /opt/gcc_3.2.3/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/../../../../i686-pc-linux -gnu/bin/as -V -Qy -o hsw.o hsw.s GNU assembler version 2.14 (i686-pc-linux-gnu) using BFD version 2.14 20030612 /opt/gcc_3.2.3/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/collect2 --eh-frame-hdr -m elf_i386 -shared -o hsw.so /usr/lib/crti.o /opt/gcc_3.2.3/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/crtbeginS.o -L/usr/local/bin -L/opt/gcc_3.2.3/lib/gcc-lib/i686-pc-linux-gnu/3.2.3 -L/opt/gcc_3.2.3/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/../../../../i686-pc-lin ux-gnu/lib -L/opt/gcc_3.2.3/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/../../.. hsw.o -lstdc++ -lstdc++ -lm -lgcc_s -lc -lgcc_s /opt/gcc_3.2.3/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/crtendS.o /usr/lib/crtn.o /opt/gcc_3.2.3/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/../../../../i686-pc-linux -gnu/bin/ld: hsw.so: undefined versioned symbol name std::time_put_w@@GLIBCPP_3.2 /opt/gcc_3.2.3/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/../../../../i686-pc-linux -gnu/bin/ld: failed to set dynamic section sizes: Bad value collect2: ld returned 1 exit status By the way: /usr/local/* is empty on that host. The binutils are the latest ones: $ which ld /opt/gcc_3.2.3/bin/ld $ ld --version GNU ld version 2.14 20030612 Let me know if you need anything else...
This must be a bug in binutils as the static library does not contain references to versioned functions.
I'm afraid that you're mistaken, please see the output of nm, which contains a couple of ...@@GLIBCPP_3.2 What is the resolution of the problem anyway? What do I have to do to make it work? $ /opt/gcc_3.2.3/bin/nm -C /opt/gcc_3.2.3/lib/libstdc++.a >& libstc-nm.txt $ /opt/gcc_3.2.3/bin/nm --version GNU nm 2.14 20030612 Copyright 2002 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License. This program has absolutely no warranty.
Created attachment 5249 [details] Output of nm -C libstdc++.a nm is from binutils 2.14
Still not a bug, you have to use also libstdc++'s linker script to do your shared library.
*** Bug 13805 has been marked as a duplicate of this bug. ***
Andrew, can you explain in a bit more detail why this shouldn't work? I thought versioned symbols should be specific to _shared_ libraries... Thanks.
Fixed for 3.4, the problem was a libtool bug.
Okay, good. I just confirmed here too that it's fixed with 3.4 branch (and so 3.4.0 will not have this problem).
(In reply to comment #13) > Okay, good. I just confirmed here too that it's fixed with 3.4 branch (and so 3.4.0 will not have this > problem). Thanks for looking into this again! I meanwhile found a work-around for gcc 3.3.2. Looking through the various configure scripts I found the undocumented option --disable-symvers. Bootstrapping the compiler with this option fixes the problem (hopefully without bad side effects). Looking forward to the 3.4 release ...
(In reply to Dirk Walther from comment #14) thanks for this hint, however I understand it requires recompile of gcc