This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: gcc 4.0.0 x86_64 static linking of libstdc++.a


On 23 May 2005, Roland Lengfeldner suggested tentatively:
> I'm facing the following problem: I want to create a shared library on Linux
> (Red Hat Enterprise 3) / Opteron, with gcc 4.0.0 & binutils 2.16. When
> compiling in 32-bit mode (with -m32) everything works, but in 64-bit mode
> (with -m64) the following error message appears:
> 
> gcc -shared   {list of .o files}  -ldl -lm
> 
> /opt/dessup/gnu_2004/gcc400/opt3/lib/gcc/x86_64-unknown-linux-gnu/4.0.0/../../../../lib64/libstdc++.a
>  -m64 -static-libgcc -fPIC 
> -Wl,-soname -Wl,libAGENT.so.1 -o .libs/libAGENT.so.1.0.0

Linking non-PIC code (as is generally contained in static libraries)
into shared libraries is not portable and can't be guaranteed to work.
(The GNU C library's dynamic linker fixes it up in many cases, but it
*will* fail on other OSes, notably Solaris).

> /opt/dessup/gnu_2004/gcc400/opt3/bin/ld:
> /opt/dessup/gnu_2004/gcc400/opt3/lib/gcc/x86_64-unknown-linux-gnu/4.0.0/../../../../lib64/libstdc++.a(functexcept.o):
> relocation R_X86_64_32 against `std::bad_typeid::~bad_typeid()' can not be
> used when making a shared object; recompile with
> -fPIC

Well, that's pretty clear: recompile libstdc++.a with -fPIC (which means
rebootstrapping GCC with distinctly unusual CXXFLAGS) or take out that
explciit linkage to libstdc++.a.

(You should be using the c++ or g++ drivers for this, anyway.)

> What does the error message mean? Is gcc 4.0.0 (or at least libstdc++.a)
> miscompiled, or is it a gcc configuration problem:

Neither: you're doing something risky, inefficient and not a good idea :/

-- 
`Once again, I must remark on the far-reaching extent of my
 ladylike nature.' --- Rosie Taylor


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]