应用程序中两个不同版本的库 [英] Two library of different versions in an application

查看:116
本文介绍了应用程序中两个不同版本的库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑一个场景,其中存在两个不同版本的共享库.请考虑将A.1.so链接到B.so,将A.2.so链接到C.so.现在B.so和C.so都链接到d.exe了.当B.so想要在A.1.so中调用函数时,最终在A.2.so中调用函数.因此,它给我们带来了不确定的行为.

Consider a scenario where there are two shared library of different version.Consider A.1.so linked to B.so and A.2.so linked to C.so. Now both B.so and C.so are linked to d.exe . When B.so wants to invoke function in A.1.so, it ends up calling function in A.2.so .Because of this , it gives us undefined behaviour.

现在我希望我的B.so只调用A.1.so.我只能修改A.1.so和B.so,没有别的.使用dlopen()是选项之一,但是对于使用dlopen(),我必须在B.so中进行大量更改.堆栈溢出中前面给出了许多解决方案,但是似乎没有任何效果.请注意,我只能在A.1.so和B.so中进行代码更改.

Now I want my B.so invoke only A.1.so.I can only modify A.1.so and B.so , nothing else. Using dlopen() is one of the option, but for using dlopen(), I have to make heavy changes in B.so. There are many solutions given earlier in Stack Overflow, but nothing seems to work. Kindly note that I can make code changes in A.1.so and B.so only.

除了dlopen()之外,是否还有其他解决方案.我已经在下面提到了一些链接.

Is there any other solution to this problem other than dlopen(). I have mentioned some of the links below.

  • https://blog.habets.se/2012/05/Shared-libraries-diamond-problem.html
  • https://code.woboq.org/qt5/qtbase/src/network/ssl/qsslsocket_openssl_symbols_p.h.html
  • https://www.mailerq.com/blog/good-reasons-to-use-dlopen
  • Loading multiple shared libraries with different versions
  • Program use two conflicting shared libraries
  • C++ two libraries depend on same lib but different versions?
  • Linking with multiple versions of a library
  • C++ two libraries depend on same lib but different versions?

推荐答案

是否可以将所有代码包装在namespace A1中的A1.cpp中,并在B.cpp中添加using namespace A1? A1.cppB.cpp是指A1.soB.so的所有相关翻译单元.

can you wrap all code in A1.cpp in namespace A1 and add a using namespace A1 to B.cpp? By A1.cpp an B.cpp I mean all the relevant translation units for A1.so and B.so.

这篇关于应用程序中两个不同版本的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆