This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: using a static library in a shared library?
- From: pkurpis at keck dot hawaii dot edu (Peter Kurpis)
- To: steve dot lindsay at misys dot com
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 15 Jul 2002 10:29:10 -1000 (HST)
- Subject: Re: using a static library in a shared library?
I think you could do this, if your .o files in the .a were compiled
with -fPIC (which is a requirement for *any* .o files going into
your .so file). (I haven't tried it, but I can't think of a reason
why it shouldn't work.)
An additional point, however, which may be relevant:
I recently was building a .so file using g++ -shared and got
similar symptoms to what you describe below, also on solaris 8.
I was *not* using a .a file, and all my .o files were compiled
with -fPIC . So it really puzzled me...
What it turned out to be was that ld was balking at three
of my .o files. I don't know why the three were singled out
from the over a dozen others, but the problem was fixed by
going from
g++ -shared ...
to
g++ -Wl,-G -Wl,-dy ...
[Note that's "capital W, lowercase ell -- not numeric one."]
Apparently, -shared passes -G and -dy to ld , as I do
in the second instance, but also passes -z text , which ld did
not like for the three .o files.
Note that I use the solaris ld (i.e. /usr/ccs/bin/ld , not the
GNU ld -- I configured gcc with the solaris ld for compatibility
reasons).
Note also that this was using g++ to link, not gcc as you do
(although I would suppose I'd have had a similar problem with gcc).
Anyways, I don't know whether this is relevant to you, but in case
it is, it's hard to figure out (at least it was for me :( ), so I
wanted to spare you some pain.
> From gcc-help-return-9525-pkurpis=keck.hawaii.edu@gcc.gnu.org Mon Jul 15 00:08:22 2002
>
> Is it possible to build a shared library that contains a static library?
> In other words, I want to create something called libmyshared.so which
> uses functions in something called libcus.a.
>
> I'm using gcc 2.95.3 on Solaris 8.
>
> When I type:
>
> gcc -shared -o libmyshared.so mytest.o
> /export/home/CASmf/SunOS/obj/libcus.a
>
> I get a huge long list like this:
>
> Text relocation remains referenced
> against symbol offset in file
> <unknown> 0x19f0
> /export/home/CASmf/SunOS/obj/libcus.a(cusapi2.o)
> <unknown> 0x19f4
> /export/home/CASmf/SunOS/obj/libcus.a(cusapi2.o)
> <unknown> 0x19f8
> /export/home/CASmf/SunOS/obj/libcus.a(cusapi2.o)
> <unknown> 0x19fc
> /export/home/CASmf/SunOS/obj/libcus.a(cusapi2.o)
> <unknown> 0x244c
> /export/home/CASmf/SunOS/obj/libcus.a(cusapiint.o)
> <unknown> 0x2450
> /export/home/CASmf/SunOS/obj/libcus.a(cusapiint.o)
>
> ending with:
>
> ld: fatal: relocations remain against allocatable but non-writable
> sections
> collect2: ld returned 1 exit status