C++ 两个库依赖于相同的库但不同的版本? [英] C++ two libraries depend on same lib but different versions?

查看:25
本文介绍了C++ 两个库依赖于相同的库但不同的版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用 GCC 编译器在 C++ 中有库 A、B 和 C.Lib A 和 B 都依赖于 C,但依赖于它的不同版本.然后我可以在另一个程序中同时使用 A 和 B 吗?或者 A 和 B 要求的 C 的不同版本会冲突吗?我该如何解决这个问题,我可以吗?

If i have libs A, B and C in C++ using GCC compiler. Lib A and B both depend on C but on different versions of it. Can i then use A and B together in another program? or will the different versions required of C by A and B conflict? And how do i resolve this and can i?

推荐答案

我假设您正在动态链接.如果 A 和 B 都完全封装了它们各自版本的 C,那么就有可能做到这一点.您可能必须确保不同版本的 C 命名不同(即 libMyC.1.so 和 libMyC.2.so)以避免在运行时加载它们时造成混淆.

I'm assuming that you're linking dynamically. If both A and B completely encapsulate their respective versions of C then it might be possible to do this. You might have to make sure that the different versions of C are named differently (i.e. libMyC.1.so and libMyC.2.so) to avoid confusion when they are loaded at runtime.

您还可以调查静态构建 A 和 B 以避免运行时负载混淆的可能性.

You could also investigate statically building A and B to avoid the possiblility of runtime load confusion.

找出答案的最简单方法就是尝试一下.应该不会花很长时间来确定它是否会起作用.

Simplest way to find out is simply to try it. It shouldn't take to long to determine if it'll work or not.

最后,当然,到目前为止,最简单的解决方案,从维护的角度来看也是最好的,是将 A 或 B 提升到另一个级别,以便它们都使用相同版本的 C.有这么多方法,我强烈建议你这样做,而不是尝试解决一个真正的问题.

Lastly, of course, by far the easiest solution, and best from a maintenance perspective is to bring A, or B, up to the level of the other so that they both use the same version of C. This is better in so many ways and I strongly urge you to do that rather than to try working around a real problem.

这篇关于C++ 两个库依赖于相同的库但不同的版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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