I get the following with the net_error.ii file attached to this bug: [pedro@localhost Projetos]$ g++ -O3 -fPIC -c -o net_error.o net_error.ii [pedro@localhost Projetos]$ g++ -fPIC -shared -o net_error.so net_error.o /usr/bin/ld: net_error.o(.text+0x8e): unresolvable relocation against symbol `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Rep::_S_empty_rep_storage@@GLIBCXX_3.4' /usr/bin/ld: final link failed: Nonrepresentable section on output collect2: ld returned 1 exit status [pedro@localhost Projetos]$ g++ -O3 -c -o net_error.o net_error.ii [pedro@localhost Projetos]$ g++ -shared -o net_error.so net_error.o [pedro@localhost Projetos]$ Works fine. [pedro@localhost Projetos]$ g++ -fPIC -c -o net_error.o net_error.ii [pedro@localhost Projetos]$ g++ -fPIC -shared -o net_error.so net_error.o [pedro@localhost Projetos]$ Works fine. [pedro@localhost Projetos]$ g++ -v Using built-in specs. Target: i386-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,java,f95,ada --enable-java-awt=gtk --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --host=i386-redhat-linux Thread model: posix gcc version 4.0.0 20050519 (Red Hat 4.0.0-8) The machine runs a Fedora Core 4 system.
Created attachment 9149 [details] Problem code This file contains the declaration for a class inheriting from std::runtime_error.
I think this is a binutils bug and not a bug in GCC and/or libstdc++.
Works in the same system with a g++ 3.4.4 compiled from source: [pedro@localhost Projetos]$ $HOME/.local/gcc-3.4.4/bin/g++ -O3 -fPIC -c -o net_error.o net_error.ii [pedro@localhost Projetos]$ $HOME/.local/gcc-3.4.4/bin/g++ -fPIC -shared -o net_error.so net_error.o [pedro@localhost Projetos]$ $HOME/.local/gcc-3.4.4/bin/g++ -v Reading specs from /home/pedro/.local/gcc-3.4.4/lib/gcc/i686-pc-linux-gnu/3.4.4/specs Configured with: ../configure --prefix=/home/pedro/.local/gcc-3.4.4 --enable-languages=c,c++ Thread model: posix gcc version 3.4.4 [pedro@localhost Projetos]$
It is a gcc bug and has been fixed in CVS: [hjl@gnu .libs]$ readelf --wide -s /usr/lib/libstdc++.so.6 | grep _ZNSs4_Rep20_S_empty_rep_s | c++filt 1536: 000e3ef8 16 OBJECT WEAK DEFAULT 25 std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Rep::_S_empty_rep_storage@@GLIBCXX_3.4 [hjl@gnu .libs]$ readelf --wide -s libstdc++.so.6 | grep _ZNSs4_Rep20_S_empty_rep_s | c++filt 1535: 000d7d18 16 OBJECT WEAK DEFAULT 25 std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Rep::_S_empty_rep_storage@@GLIBCXX_3.4 2520: 000d7d18 16 OBJECT WEAK DEFAULT 25 std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Rep::_S_empty_rep_storage *** This bug has been marked as a duplicate of 22109 ***
Wrong duplicated bug.
The real isssue is you can't use #pragma GCC visibility push(hidden) on libstdc++ and glibc since they don't support them. We need to fix both glibc and libstdc++ header files. *** This bug has been marked as a duplicate of 19664 ***
One solution is to put #pragma GCC visibility push(default) ... #pragma GCC visibility pop around all libc and libstdc++ header files, like #pragma GCC visibility push(default) #include <iostream.h> #pragma GCC visibility pop But you may run into bug 20303.
Substituting the pragma for -fvisibility=hidden also seems to solve the problem.