0

I have a program that has several libraries statically linked to it. It loads dynamic libraries (modules) that use those same libraries.

Instead of statically linking the modules, would it be somehow possible to dynamically link to the functions that already exist in the main program?

The problem I'm facing here is that the said libraries contain internal state (static variables), and if both the main program and modules are statically compiled, that internal state is duplicated to both places and the library doesn't work similarly from the main program and modules.

hotmultimedia
  • 86
  • 1
  • 6
  • No, shared state needs to be in a single shared library, shared state in static libraries means each user of the static library gets a separate state (in general, the c++ standard doesn't specify this behaviour) – Alan Birtles Apr 18 '20 at 08:31

1 Answers1

0

Since the dynamic library is build without any knowledge about the application that later loads it, it can not know what that application provides. So it needs to link to its own instance of the static library.

If you want such an architecture, you have to introduce a way for the library to get to know the functions provided by the loading application. One possible concept is to use callbacks.

the busybee
  • 10,755
  • 3
  • 13
  • 30