如何隔离第三方? C/C++/ObjC 库'彼此的符号?
我有一个项目需要合并两个第三方库libA和libB。我对第三方库的影响力即使有也很小。问题是 libA 和 libB 都包含公共库 ASIHTTPRequest 的不同版本。结果,我收到类似以下错误:
-[ASIFormDataRequest setNumberOfTimesToRetryOnTimeout:]: unrecognized selector sent to instance 0x3b4170
,我只能假设这是因为 libA 引用了 libB 的 ASIHTTPRequest 实现(或其他方式)。
我尝试过使用 strip -s
将库的符号彼此隔离,但这会导致 XCode 的链接器发出数千个警告,并且实际上并没有解决上面概述的主要问题。
ld:警告:无法将行信息添加到来自...的匿名符号 anon-func-0x0
一般来说,如何/应该如何将库彼此隔离?
I have a project that needs to incorporate two third-party libraries, libA and libB. I have little, if any, influence over the third-party libraries. The problem being is that both libA and libB include different versions of a common library, ASIHTTPRequest. As a result, I'm getting errors like:
-[ASIFormDataRequest setNumberOfTimesToRetryOnTimeout:]: unrecognized selector sent to instance 0x3b4170
, which I can only assume are because libA is referring to libB's implementation of ASIHTTPRequest (or the other way around).
I've tried playing around with strip -s <symbol file> -u <library>
to isolate the libraries' symbols from each other, but that results in XCode's linker spitting out thousands of warnings and doesn't actually fix the main problem outlined above.
ld: warning: can't add line info to anonymous symbol anon-func-0x0 from ...
In general, how can/should one isolate libraries from each other?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
绝对没有办法这样做。一个 Objective-C 应用程序一次只能对一个符号具有一种含义。如果加载一个库的两个不同版本,最后一个版本将覆盖第一个版本。
两种解决方法:
There is absolutely no way to do so. One Objective-C application can have only one meaning for one symbol at a time. If you load two different versions of one library the last one will overwrite the first one.
Two workarounds:
如果他们对不同的例程使用相同的链接器符号名称,唯一的出路(除了破解他们的目标文件)就是以某种方式将它们链接到不同的可执行文件。
在支持动态链接(例如:DLL)的平台上,您可以将其中之一或两者构建到单独的 DLL 中。如果它们不是导出界面的一部分,则符号不应发生冲突。
否则,您将不得不将它们放入完全独立的进程中并使用 IPC 在它们之间传递数据。
If they used the same linker symbol name for different routines, the only way out (short of hacking their object files), is to link them into different executables somehow.
On platforms that support dynamic linking (eg: DLLs) you could build one or both into a separate DLL. If they aren't part of the exported interface the symbols shouldn't clash then.
Otherwise you would be stuck putting them into entirely separate processes and using IPC to pass data between them.