public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Building shared library that uses libstdc++
@ 2001-04-13 10:41 Lundell, Jens O.
  2001-04-13 13:09 ` Alexandre Oliva
  0 siblings, 1 reply; 5+ messages in thread
From: Lundell, Jens O. @ 2001-04-13 10:41 UTC (permalink / raw)
  To: gcc-help

I want to build a shared library that uses the Standard C++ Library using
Solaris 7 and GCC 2.95.3. I would prefer to statically link the Standard C++
library so I don't have to distribute libstdc++.so.2.10.0. I can create a
shared library like this:

g++ -fPIC -shared -o libjens.so source.cpp

and I can statically link the Standard C++ Library to an executable like
this:

g++ -static -o jensexe source.cpp

but when I combine the two I get the following error:

ld: warning: option -d appears more than once, first setting taken
ld: fatal: option -dn and -z[text|textwarn|textoff] are incompatible
ld: fatal: option -dn and -G are incompatible
ld: fatal: Flags processing errors
collect2: ld returned 1 exit status

Do I have to distribute libstdc++.so.2.10.0 together with my shared library?
Is so, what happens if the machine already has a different version of
libstdc++, dll-hell?

-Jens

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

* Re: Building shared library that uses libstdc++
  2001-04-13 10:41 Building shared library that uses libstdc++ Lundell, Jens O.
@ 2001-04-13 13:09 ` Alexandre Oliva
  0 siblings, 0 replies; 5+ messages in thread
From: Alexandre Oliva @ 2001-04-13 13:09 UTC (permalink / raw)
  To: Lundell, Jens O.; +Cc: gcc-help

On Apr 13, 2001, "Lundell, Jens O." <JENS.O.LUNDELL@saic.com> wrote:

> g++ -fPIC -shared -o libjens.so source.cpp

> g++ -static -o jensexe source.cpp

> but when I combine the two I get the following error:

> ld: warning: option -d appears more than once, first setting taken

Do you mean, as in:

  g++ -fPIC -shared -static -o libjens.so source.cpp ?
            ^^^^^^^^^^^^^^^

This just can't work.

> Do I have to distribute libstdc++.so.2.10.0 together with my shared library?

Specify the full pathname of libstdc++.a, and use the -mimpure-text
switch, such that the linker won't complain even though libstc++.a
contains non-PIC.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

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

* RE: Building shared library that uses libstdc++
@ 2001-04-17 17:43 Lundell, Jens O.
  0 siblings, 0 replies; 5+ messages in thread
From: Lundell, Jens O. @ 2001-04-17 17:43 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: gcc-help

Thank you very much Alex, it worked. 
It would be nice if some of these common compiler switch combinations were
collected into a FAQ or something. It's not easy to correctly put all the
pieces together from the "GCC Command Options" page. Especially since some
of the information is in the wrong place, "-mimpure-text" is for example
described under AMD29K options instead of under SPARC options.

Thanks,

Jens

> Alexandre Oliva wrote:
> Jens Lundell wrote:
> > g++ -fPIC -mimpure-text -shared -o libjens.so source.cpp
> > /usr/local/lib/libstdc++.a.2.10.0
> 
> > which compiles fine but both ldd and elfdump reveals that 
> > the resulting library (libjens.so) still depends on 
> > libstdc++.so.2.10.0.
> 
> That's because g++ implicitly adds  -lstdc++ to the link command
> line.  Try -nodefaultlibs, and add -lgcc -lc -lgcc to the link command
> line.

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

* Re: Building shared library that uses libstdc++
  2001-04-16  9:44 Lundell, Jens O.
@ 2001-04-16 12:14 ` Alexandre Oliva
  0 siblings, 0 replies; 5+ messages in thread
From: Alexandre Oliva @ 2001-04-16 12:14 UTC (permalink / raw)
  To: Lundell, Jens O.; +Cc: gcc-help

On Apr 16, 2001, "Lundell, Jens O." <JENS.O.LUNDELL@saic.com> wrote:

> g++ -fPIC -mimpure-text -shared -o libjens.so source.cpp
> /usr/local/lib/libstdc++.a.2.10.0

> which compiles fine but both ldd and elfdump reveals that the resulting
> library (libjens.so) still depends on libstdc++.so.2.10.0.

That's because g++ implicitly adds  -lstdc++ to the link command
line.  Try -nodefaultlibs, and add -lgcc -lc -lgcc to the link command
line.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

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

* RE: Building shared library that uses libstdc++
@ 2001-04-16  9:44 Lundell, Jens O.
  2001-04-16 12:14 ` Alexandre Oliva
  0 siblings, 1 reply; 5+ messages in thread
From: Lundell, Jens O. @ 2001-04-16  9:44 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: gcc-help

>> Jens Lundell wrote:
>> Do I have to distribute libstdc++.so.2.10.0 together with my shared
library?

> Alexandre Oliva wrote:
> Specify the full pathname of libstdc++.a, and use the -mimpure-text
> switch, such that the linker won't complain even though libstc++.a
> contains non-PIC.

I tried,

g++ -fPIC -mimpure-text -shared -o libjens.so source.cpp
/usr/local/lib/libstdc++.a.2.10.0

which compiles fine but both ldd and elfdump reveals that the resulting
library (libjens.so) still depends on libstdc++.so.2.10.0.

-Jens

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

end of thread, other threads:[~2001-04-17 17:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-13 10:41 Building shared library that uses libstdc++ Lundell, Jens O.
2001-04-13 13:09 ` Alexandre Oliva
2001-04-16  9:44 Lundell, Jens O.
2001-04-16 12:14 ` Alexandre Oliva
2001-04-17 17:43 Lundell, Jens O.

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).