I have an executable E which (I assume) dynamically loads (dlopen) a library file A.so. File A.so dynamically links B.so which is produced by me. In B.so I statically link a number of libraries, e.g. Boost (let’s call this static boost library C1). Only B is fully under my control. A only partially (I can add some linker flags, for example).
It seems that E is also linking an older version of Boost dynamically. Let’s call this Boost library C2. When I run E and code from B is used, it resolves Boost symbols from C2 (more specifically regarding the serialization library) and this causes crashes as those are not compatible with the code in B which statically links C1.
How can I make sure B is always using the symbols from the statically linked Boost library and not from any dynamically linked library? Or more general, I actually want to ensure this for all libraries I statically link into B.
Some more information:
- I checked the dependencies of B with
lddand they do not refer to a Boost library.
- I think the problem might be due C2 exporting serialization symbols and B exporting weak symbols (inspected using
nm -D). I cannot change C2 and I am not sure how to hide the weak Boost symbols in B.
- I use the
ldto control which symbols I want to export from B.
- I also tried using the
--dynamic-listinstead of using the
- I tried using
--whole-archivewhen linking the static libraries into B, but it did not solve the issue.
- I do not want to use the
visibility attributein my code, as I want to be able to link the same code using different export configurations.