我有两个库A
和B
. 那里有相同的功能same_func
,我不想修改A
代码以删除但same_func
在A
链接时覆盖符号。如果符号冲突,是否有任何方法可以指示B
lib 中具有更高优先级的函数首先被选择。
问问题
161 次
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 回答