静态和动态链接相同的库 [英] Statically and dynamically linking the same library

查看:112
本文介绍了静态和动态链接相同的库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,是静态链接库( libA.2.0.a ),并动态地链接到另一个库( libB.so )。 libB.so 也是动态的链接到一个旧版本力霸( libA.1.0.so )。

I have a program that's statically linking to a library (libA.2.0.a) and also dynamically links to another library (libB.so). libB.so also dynamically links to an older version of libA (libA.1.0.so).

这是配置可以吗?如果是这样,系统怎样知道使用从 libA.2.0.a 我的程序的符号和符号从 libA.1.0.so libB.so

Is this configuration possible? And if so, how does the system know to use the symbols from libA.2.0.a for my program and the symbols from libA.1.0.so for libB.so?

推荐答案

是的,这样的配置是可能的。

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.

在构建libB.so,它建立其对libA.1.0.so.链接它不知道或关心使用它会做什么其他的应用程序,它只是知道如何绘制自己的函数调用。

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.

在构建应用程序本身,应用程序链接到libB.so.无论libB.so要求是完全未知的应用程序。该应用程序还静态链接到一个库,libB.so不关心。

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.

有一个问题:如果力霸使用静态变量,会出现一个设置为libB.so访问静态的,而不同的,独立的一套应用程序访问的静力学。

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.

这篇关于静态和动态链接相同的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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