简体   繁体   English

链接所有链接到公共静态库的多个共享库

[英]Linking against multiple shared libraries that all linked against a common static library

Say you have 2 share libraries, lib1.so and lib2.so, that both have libcommon.a statically linked into them. 假设您有两个共享库lib1.so和lib2.so,它们都将libcommon.a静态链接到它们中。 Would the compiler complain about ambiguous symbol reference if you were to dynamically link both lib1.so and lib2.so? 如果要动态链接lib1.so和lib2.so,编译器是否会抱怨模糊的符号引用? Or would be the compiler be smart enough to know libcommon symbols are shared between lib1 and lib2 and allow you to dynamically link against both? 或者编译器是否足够聪明,知道lib1和lib2之间共享libcommon符号,并允许您动态链接两者?

There won't be a conflict because when you link to shared libraries, the linker will use the definition from the first shared library which provides the symbol and won't look further at the other shared libraries. 不会发生冲突,因为链接到共享库时,链接器将使用第一个提供符号的共享库中的定义,而不会进一步查看其他共享库。 Symbols included from the .a will be exported in both shared libraries but won't conflict. .a中包含的符号将在两个共享库中导出,但不会发生冲突。

The static library would be used to resolve the links internally but the external linkage would not be propagated to the shared library interface, so there would be no conflict. 静态库将用于内部解析链接,但外部链接不会传播到共享库接口,因此不会发生冲突。 Each shared library would include its own copy of the static library code. 每个共享库都包含自己的静态库代码副本。

Suppose the two shared libraries linked with the different static libraries. 假设两个共享库与不同的静态库链接。 But the static libraries both contain a function with the same name. 但静态库都包含一个具有相同名称的函数。 There would be conflict. 会有冲突。

I'm sure of that because I have a tcl/tk application, it load two tcl libraries(.so). 我很确定,因为我有一个tcl / tk应用程序,它加载了两个tcl库(.so)。 Both of the libraries are static linked with the openssl library. 这两个库都与openssl库静态链接。 but with different version. 但是版本不同。 A segmentation fault occurred when I run the tcl application. 运行tcl应用程序时发生分段错误。 I trace it into the openssl. 我将它追踪到openssl中。 There is a function implementation changed in the new version. 新版本中更改了功能实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM