Statically and dynamically linking the same library

限于喜欢 提交于 2019-12-04 19:42:36

Yes, this configuration is possible.

In answer to your question as to how the system knows how to use the symbols, remember that all of the links happen at build time. After it's been built, it isn't a question of "symbols", just calls to various functions at various addresses.

When building libB.so, it sets up it's links to libA.1.0.so. It does not know or care what other applications that use it will do, it just knows how to map its own function calls.

When building the application itself, the application links to libB.so. Whatever libB.so calls is completely unknown to the application. The application also statically links to a library, which libB.so does not care about.

One gotcha: if libA uses static variables, there will be one set of statics accessible to libB.so, and a different, independent set of statics accessible to the application.

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