public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Query related to library linking.
@ 2012-08-20  7:46 Tayade, Nilesh
  2012-08-20 20:22 ` Andrew Haley
  0 siblings, 1 reply; 2+ messages in thread
From: Tayade, Nilesh @ 2012-08-20  7:46 UTC (permalink / raw)
  To: gcc-help

Hi,

I have a basic query related to linking of static and dynamic libraries.

My program needs to use 'libcrypto', libssl and libnetsnmp libraries.
Out of these, the libnetsnmp and libssl have dependency on libcrypto.
For some reason, I need to link the libcrypto and libssl statically to my program.
So I have built libcrypto.a and libssl.a and I am able to link them correctly.

But when libnetsnmp gets linked, since it is a shared object, it also links libcrypto.so.
So why should libnetsnmp again try to link libcrypto.so when the symbols are already resolved while statically linking libcrypto.a?
Is there some way to avoid it? I tried using -static and -Bstatic.

Any advice on this will be appreciated.

--
Thanks,
Nilesh
P.S. : I tried looking for any clue in archives. Please redirect me to the link, if such queries are already answered.


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

* Re: Query related to library linking.
  2012-08-20  7:46 Query related to library linking Tayade, Nilesh
@ 2012-08-20 20:22 ` Andrew Haley
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Haley @ 2012-08-20 20:22 UTC (permalink / raw)
  To: Tayade, Nilesh; +Cc: gcc-help

On 08/20/2012 05:53 AM, Tayade, Nilesh wrote:

> I have a basic query related to linking of static and dynamic libraries.
> 
> My program needs to use 'libcrypto', libssl and libnetsnmp libraries.
> Out of these, the libnetsnmp and libssl have dependency on libcrypto.
> For some reason, I need to link the libcrypto and libssl statically to my program.
> So I have built libcrypto.a and libssl.a and I am able to link them correctly.
> 
> But when libnetsnmp gets linked, since it is a shared object, it also links libcrypto.so.
> So why should libnetsnmp again try to link libcrypto.so when the symbols are already resolved while statically linking libcrypto.a?

Because libnetsnmp has a run-time dependency on libcrypto, not a compile-
time dependency.

> Is there some way to avoid it? I tried using -static and -Bstatic.

It's going to be very difficult.  C has a "One Definition Rule" which
says that in any running program there must only be one definition of
each symbol.  Clearly, what you're trying to do will violate that
rule.

I would seriously try to find a way to link your program against
libcrypto.so.

Andrew.

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

end of thread, other threads:[~2012-08-20 11:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-20  7:46 Query related to library linking Tayade, Nilesh
2012-08-20 20:22 ` Andrew Haley

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