How to make sure statically linked Boost is used in dynamic library file

I have an executable E which (I assume) dynamically loads (dlopen) a library file File dynamically links which is produced by me. In 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 ldd and 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 --retain-symbols-file option of ld to control which symbols I want to export from B.
  • I also tried using the --version-script or --dynamic-list instead of using the --retain-symbols-file option.
  • I tried using -Bsymbolic together with --whole-archive when linking the static libraries into B, but it did not solve the issue.
  • I do not want to use the visibility attribute in my code, as I want to be able to link the same code using different export configurations.

Source: c++

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.