views:

87

answers:

2

I have an application X which uses shared libraries A,B and C. Shared library C also uses some symbols from Shared library A. Application X is linked against A and B during compile time and it does dlopen to load C at run time. My question is

  1. Is it a good idea to link C against A during link time or leave the symbol resolution for runtime?
A: 

I would go with the option 2. Leave the resolution for runtime. Late binding is the best option. Also I never knew that option 1 was possible :)

Himanshu
+2  A: 

Your option 1. But it does not work that way.

  1. You link C with A.
    As A is a dynamic lib this will do nothing phsically.
    It verifies that all dependencies will be satisfied by A at runtime.

  2. At runtime when you dlopen() the shared lib C
    It will open C and if you had not already linked against A it would also open A
    But since A is already open it will just resolve symbols in C with the A that is open.

Martin York
There could be a problem if the application and library C are linked to different major versions of library A. Then both major versions will get loaded and their symbols will mix, unless there's symbol versioning.
Dmitry Yudakov
Yes. But that is a separate problem. Let us try and focus on the problem at hand (which in this case is a non issue). If we want to get into versioning then the OP should post a specific question about it.
Martin York