Loading two instances of a shared library

后端 未结 2 858
逝去的感伤
逝去的感伤 2020-12-06 05:36

For a test I\'d like to load two instances of a shared library from an application. The code in the library provides an API but it does not allow me to initialize two (or mo

相关标签:
2条回答
  • 2020-12-06 06:05

    You can load a library twice, in theory, if it's compiled as position-independent code (-fPIC).

    On some Unices, you can then dlopen the library twice if your loader has an RTLD_PRIVATE flag, or by having two "different" copies of the library with the same symbols (put it at two different paths, otherwise it will just return the first file handle), and opening them each with RTLD_LOCAL.

    I don't know anything about Windows shared libraries. It may not even be possible.

    0 讨论(0)
  • 2020-12-06 06:27

    On windows at least, you could just rename the library, and load both of them.

    0 讨论(0)
提交回复
热议问题