C++ two libraries depend on same lib but different versions?(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++ 两个库依赖于相同的库但不同的版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++ 两个库依赖于相同的库但不同的版本?


基础教程推荐
- 我有静态或动态 boost 库吗? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 这个宏可以转换成函数吗? 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01