kumar
kumar

Reputation: 2806

Is it good to link a shared library against other shared libraries?

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:

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

Upvotes: 0

Views: 1646

Answers (2)

Loki Astari
Loki Astari

Reputation: 264551

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.

Upvotes: 2

Himanshu
Himanshu

Reputation: 1999

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

Upvotes: 0

Related Questions