1

Let's say my software project, A, ships as a shared library (libA.so). A uses a 3rd party library, B, which it links as a shared library when I build libA.so. (Though I'm happy to use libB.a rather than libB.so if that is part of the solution.) B is used by A, but strictly speaking, the apps that link against A don't need to see any of the symbols of B, it's not part of A's public API.

OK, here's the problem: some apps link against B for their own reasons, as well as against A, and if the versions of B (the one the app uses and the one A linked against at build time) don't match, there are random crashes as the symbols clash.

How can I cause all of B's symbols to resolve against A's needs, but not export as visible symbols in libA.so? In other words, I don't want an app linking against A to ever directly resolve against B's symbols. Is that even possible?

Primarily, I need a solution on Linux, though knowing how to solve the problem on OSX and/or Windows will also be helpful down the road.

I understand how to restrict visibility of the symbols in A itself (that aren't necessary to be part of the public API of A), but how do I do this for dependent library B?

Larry Gritz
  • 13,331
  • 5
  • 42
  • 42

1 Answers1

1

... some apps link against B for their own reasons ... In other words, I don't want an app linking against A to ever directly resolve against B's symbols.

Think about it: if you prevent the app from linking against B's symbols, how would the app satisfy "its own reason to link against B" ?

Your question (as stated) is self-contradictory.

Now, multiple versions of B used to link different parts of the same executable are clearly a problem.

The only solution I know of is for you to "hide" the fact that you are using B completely. The way to do that is:

  1. Link against libB.a, and
  2. Hide B's symbols inside libA.so, so they are not exported. This is easiest to achieve with a linker version script.

Please note that if libB.a is distributed under e.g. GPL, putting a copy of it into libA.so may require that you satisfy libBs licensing terms. Tread carefully and consult your lawyer.

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