This is the mail archive of the gcc@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]

Re: Building libstdc++ non-shared with -fpic ?


> I complained about this to some folks (e.g. the Mozilla team),
> and said that gcc doesn't even build libstdc++ as shared library
> when build with the default configuration.

Yes, it is not the default, because if it was, it might not work in
the end - applications may not find libstdc++.so, when it is not on
the LD_LIBRARY_PATH. So administrators have to locally arrange that
everybody will find the shared libraries, therefore it is an
administrative decision. On Linux, gcc is normally installed into
/usr, in which case it is safe to activate --enable-shared; most
distributors do.

> Now if you try to build a shared library, which uses code of a 
> static libstdc++, this will lead to problems, because the
> static libstdc++ will contain code which is NOT position 
> independent. 

No, it won't lead to problems - at least not if these two library
copies had the same source code, and where compiled by the same
compiler release. You can certainly combine non-PIC code into a shared
library, at least on Linux.

> A resolution to this problem seems to compile libstdc++ as
> static library BUT with the -fpic option, so that the code
> included in the static archive is PIC.

You don't have to; it will work even without -fPIC.

> I browsed through the configuration files of gcc-2.95.2
> and found out that the libstdc++ will only be build in
> PIC, if it is also build as a shared library. (no surprise)
> 
> Could this be changed ? Or won't this work anyway...

This does not need to be changed. If you want to build libstdc++ with
additional flags, just put the flags into the Makefile after
configuring, or set CXXFLAGS appropriately.

Regards,
Martin


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