如何连接解决了动态库重复的符号? [英] How does linker resolves duplicate symbols in dynamically loadable libraries?

查看:713
本文介绍了如何连接解决了动态库重复的符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个动态库lib_smtp.so和和libpop.so等双方有一个名为全局变量协议被初始化为SMTP和POP分别。我有libhttp.a其中协议初始化为HTTP另一个静态库。

I have two dynamically loadable libraries lib_smtp.so and and libpop.so etc. Both have a global variable named protocol which is initialized to "SMTP" and "POP" respectively. I have another static library libhttp.a where protocol is initialized to "HTTP".

现在由于某种原因,我需要编译所有动态可链接和可加载库静态和包括可执行文件。这样做我得到错误的静态库的链接十一五期间的多个符号的定义。

Now for some reason i need to compile all dynamic linkable and loadable libraries statically and include in the executable. Doing so i am getting error "multiple definition of symbol" during linking of static libraries.

我很好奇地想知道链接器如何解决,所有三提库越来越链接动态链接过程中重复的符号?

I am curious to know how linker resolves duplicate symbols during dynamic linking where all three mentioned libraries are getting linked ?

有一些方法我可以做同样的静态作为连接器是动态的,即做链接,没有任何冲突添加所有静态库的可执行文件,具有相同的符号?如果不是,为什么这个过程是静态链接库不同。

Is there some way i can do the same statically as linker is doing in dynamic linking ie without any conflict add all static libraries to executable which have same symbols? if not, why the process is different for statically linked libraries.

推荐答案

在现代的Linux和其他几个操作系统的动态链接是基于ELF二进制格式。在其上的可执行文件或其他共享库的依赖(ELF)动态库优先。为解决给定的符号,动态连接器会检查优先级顺序每个库,直到它找到一个定义符号。

Dynamic linking in modern Linux and several other operating systems is based on the ELF binary format. The (ELF) dynamic libraries on which an executable or other shared library relies are prioritized. To resolve a given symbol, the dynamic linker checks each library in priority order until it finds one that defines the symbol.

这可能是冒险当多个动态对象定义相同的符号,也是多个动态物体的使用的那个符号。然后,它可以是该符号在不同的动态对象不同地解决的情况。

That can be dicey when multiple dynamic objects define the same symbol and also multiple dynamic objects use that symbol. It can then be the case that the symbol is resolved differently in different dynamic objects.

全部细节超出范围的SO,但我不知道一个比乌尔里希Drepper的文章更好的技术说明的如何写共享库

Full details are out of scope for SO, but I don't know a better technical explanation than the one in Ulrich Drepper's paper "How to Write Shared Libraries".

这篇关于如何连接解决了动态库重复的符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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