0

我有两个库AB. 那里有相同的功能same_func,我不想修改A代码以删除但same_funcA链接时覆盖符号。如果符号冲突,是否有任何方法可以指示Blib 中具有更高优先级的函数首先被选择。

4

2 回答 2

1

The order of the libraries on the command line commonly decides. Put library "B" before library "A".

If your application has a reference to same_func() and you set library "B" as the first one, the linker will resolve it to B's same_func(). Since the reference is resolved now, linking with library "A" will only resolve the references not yet resolved.

于 2021-03-12T07:38:28.140 回答
0

更安全的解决方案可能是将 libA 中的所有或相关符号设为“弱”。您可以使用选项 --weaken 使用 objcopy 执行此操作。这将确保链接器从 libB 中选择定义(如果它在 A 和 B 中都可用)。另一种解决方案是使用链接器脚本来包含或排除特定对象的特定部分。

于 2021-03-21T16:01:32.730 回答