dlopen of several lib

A

Anthony Catel

I have a program which load two lib (A and B).
In A i want to use some symbols of B. The problem is that lib A is
loaded before B and I get :
" undefined symbol: foo".

What is the best way to solve this kind of case ?
Load B in all lib where I use it ?

What pattern is generaly used for plugins system with dependency between
them ?

Thanks ;)
 
A

Antoninus Twink

I have a program which load two lib (A and B).
In A i want to use some symbols of B. The problem is that lib A is
loaded before B and I get :
" undefined symbol: foo".

What is the best way to solve this kind of case ?
Load B in all lib where I use it ?

The best way is, when you're linking A, to link against B. This will
record B as a dependency of A, and when you dlopen() the library A,
you'll automatically load its dependent B too (and so on recursively, if
necessary).

Of course, you should make sure that you're exporting all symbols
properly (e.g. by giving the -rdynamic option to gcc).
 
A

Anthony Catel

Thanks for your answer.

So, I can compile B like that :

gcc -Wl,-soname,libA.so.1 -rdynamic -o lib/libA.so libA.c


and A like that ? :

gcc -Wl,-soname,libB.so.1 -o lib/libB.so libB.c -L./lib -lA


Thanks ;)

Antoninus Twink a écrit :
 
K

Keith Thompson

Anthony Catel said:
I have a program which load two lib (A and B).
In A i want to use some symbols of B. The problem is that lib A is
loaded before B and I get :
" undefined symbol: foo".

What is the best way to solve this kind of case ?
Load B in all lib where I use it ?

What pattern is generaly used for plugins system with dependency between
them ?

This isn't something that's specified by the lnaguage. You're likely
to get better answers in a newsgroup that deals with your system;
since you mentioned dlopen in the subject header, that's probably
comp.unix.programmer.
 
S

Stephen Sprunk

Anthony said:
Thanks for your answer.

So, I can compile B like that :

gcc -Wl,-soname,libA.so.1 -rdynamic -o lib/libA.so libA.c


and A like that ? :

gcc -Wl,-soname,libB.so.1 -o lib/libB.so libB.c -L./lib -lA

Since this is all gcc-specific, you will get better answers over on
gnu.gcc.help.

<OT>
The example above appears to link B against A, whereas it sounds like
you need to link A against B, since A needs a symbol that's in B.
</OT>

S
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top