Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking against multiple shared libraries that all linked against a common static library

Tags:

c

linux

linker

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?

like image 270
live2dream95 Avatar asked Mar 08 '10 18:03

live2dream95


2 Answers

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.

like image 199
Jay Walker Avatar answered Sep 28 '22 05:09

Jay Walker


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.

like image 30
Clifford Avatar answered Sep 28 '22 07:09

Clifford