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

时间:2022-02-21 20:10:11

Say you have 2 share libraries, lib1.so and lib2.so, that both have libcommon.a statically linked into them. Would the compiler complain about ambiguous symbol reference if you were to dynamically link both lib1.so and 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.so和lib2.so,它们都将libcommon.a静态链接到它们中。如果要动态链接lib1.so和lib2.so,编译器是否会抱怨模糊的符号引用?或者编译器是否足够智能,以便知道lib1和lib2之间共享libcommon符号,并允许您动态链接两者?

3 个解决方案

#1


2  

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.

静态库将用于内部解析链接,但外部链接不会传播到共享库接口,因此不会发生冲突。每个共享库都包含自己的静态库代码副本。

#2


3  

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中包含的符号将在两个共享库中导出,但不会发生冲突。

#3


0  

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). Both of the libraries are static linked with the openssl library. but with different version. A segmentation fault occurred when I run the tcl application. I trace it into the openssl. There is a function implementation changed in the new version.

我很确定,因为我有一个tcl / tk应用程序,它加载了两个tcl库(.so)。这两个库都与openssl库静态链接。但是版本不同。运行tcl应用程序时发生分段错误。我将它追踪到openssl中。新版本中更改了功能实现。

#1


2  

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.

静态库将用于内部解析链接,但外部链接不会传播到共享库接口,因此不会发生冲突。每个共享库都包含自己的静态库代码副本。

#2


3  

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中包含的符号将在两个共享库中导出,但不会发生冲突。

#3


0  

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). Both of the libraries are static linked with the openssl library. but with different version. A segmentation fault occurred when I run the tcl application. I trace it into the openssl. There is a function implementation changed in the new version.

我很确定,因为我有一个tcl / tk应用程序,它加载了两个tcl库(.so)。这两个库都与openssl库静态链接。但是版本不同。运行tcl应用程序时发生分段错误。我将它追踪到openssl中。新版本中更改了功能实现。