public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: using a static library in a shared library?
@ 2002-07-15 13:29 Peter Kurpis
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Kurpis @ 2002-07-15 13:29 UTC (permalink / raw)
  To: steve.lindsay; +Cc: gcc-help


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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* using a static library in a shared library?
@ 2002-07-15  3:08 Lindsay, Steve
  0 siblings, 0 replies; 2+ messages in thread
From: Lindsay, Steve @ 2002-07-15  3:08 UTC (permalink / raw)
  To: 'gcc-help@gcc.gnu.org'

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

I've looked through the GCC documentation and haven't found an answer to
this question.  Could someone point me in the right direction, or tell
me if what I'm trying to do is possible?

Thanks,
Steve Lindsay

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-07-15 20:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-15 13:29 using a static library in a shared library? Peter Kurpis
  -- strict thread matches above, loose matches on Subject: below --
2002-07-15  3:08 Lindsay, Steve

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).