What happens when ld link different versions of the same library

209 views Asked by At

Let's say I have libA.so with version 1.1 and 1.2, both have the same symbols defined.

what happens if myApp need a symbol from libA but mistakenly linked both versions:

ld -o myApp -Lpath -lA_1_1 -lA_1_2

Am I right it will use symbols from the first one as long as it can find it?

1

There are 1 answers

0
Jonathan Wakely On BEST ANSWER

Am I right it will use symbols from the first one as long as it can find it?

Yes, in general. And that might not be what you want.

If a function foo() in libA_1_2 calls another public function in the library, bar(), then it will use the symbol from libA_1_1, which might do the wrong thing (for example if v1.2 of the library was changed so that foo() expects bar() to deallocate some memory, but the v1.1 version of bar() doesn't do that).