0

i have an executable which use two shared lib(shar1.so, shar2.so) the shared lib use use same static lib(stat.a)

but that is not creating any linker errors as multiple definations.

not able to get the reason.

Giri
  • 35
  • 5
  • check this link http://stackoverflow.com/questions/678254/what-should-i-do-if-two-libraries-provide-a-function-with-the-same-name-generati/678309#678309 – sack92 Oct 16 '15 at 09:35

1 Answers1

0

not able to get the reason.

The reason is very simple: shared libraries on UNIX are designed to behave the same way archive libraries behave.

Suppose you have foo1.o which defines function foo, and foo2.o that also defines foo (perhaps with different implementation). Suppose you put foo1.o into libfoo1.a and foo2.o into libfoo2.a.

If you understand how UNIX linkers work with archive libraries, you can predict what would happen when you link your program like this:

gcc -o t main.o -L. -lfoo1 -lfoo2   # or
gcc -o t main.o -L. -lfoo2 -lfoo1

Well, if you now link foo1.o into libfoo1.so and foo2.o into libfoo2.so, and use above commands, the exact same behavior will happen (even though details of how that behavior will happen are very different).

Employed Russian
  • 199,314
  • 34
  • 295
  • 362