每个未定义的符号是否都与它来自的库名称相关联?

Is every undefined symbol associated with the library name it comes from?

假设 libA.so 取决于 libB.so、libC.so、libD.so。未定义的符号与需要的库名之间是否存在映射:

undefined_symbol_1 comes from libB.so
undefined_symbol_2 comes from libC.so
undefined_symbol_3 comes from libC.so
undefined_symbol_4 comes from libC.so
undefined_symbol_5 comes from libD.so

或者它们只是分开存放:

Undefined symbols: undefined_symbol_1, undefined_symbol_2, undefined_symbol_3, undefined_symbol_4, undefined_symbol_5;
Required libraries: "libB.so", "libC.so", "libD.so";

系统:ubuntu

工具:g++

Linux / elf 格式中没有这样的映射。未解析的符号和所需的库不相关。

事实上,您可以预加载(使用 LD_PRELOAD)另一个解析任何未解析符号的库。这种方法通常用于在不重新编译可执行文件的情况下用另一个堆实现替换 libc malloc 和朋友。

解析符号时,运行 时间链接器按照加载的顺序遍历加载的可执行文件和库的列表,并选择第一个解析符号的。

推荐阅读:How to write shared libraries by Ulrich Drepper.