how to build shared library link to a static library

Poe, Daryl (Thin Clients) daryl.poe@hp.com
Wed Apr 24 17:50:00 GMT 2019


I agree that adding fPIC will solve your particular problem; the bigger question is whether there is any reason you would *not* want to add that flag to the components in a static library.   I do not know the answer to that question.
Daryl

-----Original Message-----
From: Wu, Wendy 
Sent: Wednesday, April 24, 2019 9:23 AM
To: Jonathan Wakely <jwakely.gcc@gmail.com>
Cc: gcc-help@gcc.gnu.org; Poe, Daryl (Thin Clients) <daryl.poe@hp.com>
Subject: RE: how to build shared library link to a static library

Thank you very much.

-----Original Message-----
From: Jonathan Wakely <jwakely.gcc@gmail.com>
Sent: Wednesday, April 24, 2019 10:21 AM
To: Wu, Wendy <jian.wu3@hp.com>
Cc: gcc-help@gcc.gnu.org
Subject: Re: how to build shared library link to a static library

On Wed, 24 Apr 2019 at 15:42, Wu, Wendy <jian.wu3@hp.com> wrote:
>
> Hi GCC team member,
> I am using 64 bit Linux.
> I have a library : libstatic.a, which has function: sfun(); I need to 
> build a library: libshared.so, which uses sfun(); but I got error “ `.rodata' can not be used when making a shared object; recompile with -fPIC”
> Add -fPIC to libstatic.a Makefile could resolve the issue.
> libstatic.a team reject to add this option, and they told me -fPIC is only for shared library.

-fPIC is for relocatable code. If you want to include code in a shared library it needs to be relocatable.

> I checked gcc document, it shows -fPIC is for shared library too.
> Could you tell me how to resolve my problem? What’s the official way to link a static 64 bit library to a shared 64bit library?

Either don't use libstatic.a or build it with -fPIC.



More information about the Gcc-help mailing list