How can I isolate third-parties' C/C++/ObjC libraries' symbols from each other?

大憨熊 提交于 2019-12-02 05:17:22

问题


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?


回答1:


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:

  1. convince the developer to use a recent version
  2. run both libraries in separate processes



回答2:


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.



来源:https://stackoverflow.com/questions/3558394/how-can-i-isolate-third-parties-c-c-objc-libraries-symbols-from-each-other

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!