How do you call a function with the same character in 2 different shared libraries?

I have several versions of the same library written in C ++. I need to compare them side by side. These libraries use the same namespace, function names and take the same parameters.

Are there any methods to control the version of the library that I use when I link two or more of them at the same time?

+4
source share
1 answer

You cannot link two libraries with the same symbols and access both. However, you can create your own thin shell libraries to eliminate two versions of the libraries:

  • Define an abstract Wrapper class that acts as a target library using abstract virtual functions
  • Define a Wrapper implementation in a class called WrapperImpl that accesses the target library from virtual methods
  • Define a standalone Wrapper *MakeImpl return new WrapperImpl()
  • Compile WrapperImpl into static libraries several times, each time linking them to different versions of the target library. Critical: pass -DWrapperImpl=WrapperImplV1 -DMakeImpl=MakeImplV1 compiler with V1 , V2 , V3 , etc. for different versions. You must have several libraries.
  • Link your core tester to these several libraries

At this point, your main tester has access to the stand-alone functions MakeImplV1 , MakeImplV2 , MakeImplV3 , etc., created by renaming MakeImpl through a preprocessor. Use these functions to obtain instances of Wrapper that migrate to different versions of the target library.

+5
source

Source: https://habr.com/ru/post/1443468/


All Articles