tags:

views:

211

answers:

2

Say you have 2 share libraries, lib1.so and lib2.so, that both have libcommon.a statically linked into them. Would the compiler complain about ambiguous symbol reference if you were to dynamically link both lib1.so and lib2.so? Or would be the compiler be smart enough to know libcommon symbols are shared between lib1 and lib2 and allow you to dynamically link against both?

+3  A: 

The static library would be used to resolve the links internally but the external linkage would not be propagated to the shared library interface, so there would be no conflict. Each shared library would include its own copy of the static library code.

Clifford
At least under GNU/Linux, If I create a shared library (.so) which links to a static library (.a), I can access any of the symbols pulled in from the static library from an executeable which links only to the shared (.so) library, so I'm pretty sure that the symbols from the static library _are_ propagated through to the shared library's interface. Maybe things work differently on some other systems, but most systems I've worked on this is the case with the default linker options.
Jay Walker
@Jay Walker: For what it is worth, I preferred your answer. Regardless of the mechanisms the fundamental truth is that no conflicts will occur.
Clifford
+1  A: 

There won't be a conflict because when you link to shared libraries, the linker will use the definition from the first shared library which provides the symbol and won't look further at the other shared libraries. Symbols included from the .a will be exported in both shared libraries but won't conflict.

Jay Walker