This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

What is the right way to link static and shared libraries together?


Hi,

This is not only binutils related, but i hope to find here some experts
knowing the answer.

When you have 2 libraries A and B. A is static and B is shared. Then you
have an executable C which uses only function of B. And B call function from
A. How do you link B and C?

I think there a two different solutions.

LINK -shared B.o -o libB.so
LINK C.o -o C -lB -lA

 - or -

LINK -shared B.o -o libB.so -lA
LINK C.o -o C -lB

I like the second one better, cause you build a self contained shared
library B. And the executable can link with B without knowing library A.

So far so good.

But what if you have two shared libraries B1 and B2? Both need some
functions from A. And the executable now calls B1 and B2.

When you now link the static library A into B1 and B2, i think you'll wind
up with two copies of A when running the executable. At least on AIX and gcc
i observed this behavior.

But you can also choose way (1) from above and link all static libraries
only to the executable. But then you have no longer self contained shared
libs.


So what is the right way in this situation with two shared libs?


Thanks in advance

  Joerg Richter 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]