Resolving C/C++ library version conflicts, mainly on Linux

南笙酒味 提交于 2021-01-27 20:30:36

问题


I have a situation more or less as illustrated here; it exists both on Windows and Linux, but I’ll draw it using Linux notation which is slightly clearer:

libbar.so.1 and libbar.so.2 contain procedures with the same names and signatures but different behaviours. If I link the applications ‘naïvely’, then symbols from the library that is loaded last will ‘hide’ the ones from the one that is loaded first (at least, if I understand this reference correctly) and I have no way of using both libraries at the same time nor determining which library’s symbols actually get used on the day.

Certainly, the error messages I’m getting at runtime are consistent with this mental model.

Now, if I could recompile all the libraries, then as described in the reference I could use the –default-symver option (at least when compiling with and linking with gcc) to disambiguate fully the symbols from each library, and force libfoo.so to look for the function baz@@libbar.so.1 and the application to look for the function baz@@libbar.so.2 with no ambiguity.

What, though, if I can only recompile my application and libbar.so.2? Will libfoo.so ignore the function baz@@libbar.so.2, or will it look no further than the baz part of it and, potentially, still use it instead of the one in libbar.so.1?

It’s a full cross-platform application so I have exactly the same issue to address on Windows. Here, I have an inkling that I may be able to use the SxS mechanism as the situation isn’t all that different from, say, having an application compiled in VS2019 that links to a library compiled in VS2013; so that the application would need to link to one version of the runtimes and the library would need to link to the other. But whilst I know how to handle this with system libraries, I’m less sure how to proceed with other libraries.

来源:https://stackoverflow.com/questions/63988087/resolving-c-c-library-version-conflicts-mainly-on-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!