1
votes

using gcc 4.5.1 in a 64bit x86 machine,I first create a.o as following: g++ -fPIC -c a.cc -o a.o

then try to create liba.so as following: g++ -static-libstdc++ -shared -W1,-soname,liba.so -o liba.so.1.0.0 a.o

but failed, with the following information: relocation R_X86_64_32S against `vtable for __gnu_cxx::stdio_filebuf >' can not be used when making a shared object; recompile with -fPIC

I try to recompile libstdc++ library,with -fPIC added,but it failed anyway

2
did you get a different error when you tried g++ -fPIC -static-libstdc++ -shared -W1,-soname,liba.so -o liba.so.1.0.0 a.o?Flexo♦

2 Answers

0
votes

I would expect that the static libstdc++ library was not build with -fPIC, and therefore can't be linked into a shared library.

Theoretically you could put non-PIC compiled code into a dynamic library, but it wouldn't be sharable (each program using it would have to have its own copy) so it's often not implemented.

You're going to need to link against the shared C++ library, make your own library a static library, or else rebuild libstdc++ yourself and grab the .o files from the build directory.

0
votes

There is a similar question about this topic on stackoverflow, which refers to an external site about static linking of libstdc++.