1

I have to use a 3rd-party framework in my app. But when I include the framework in my project I get linker errors like the following:

duplicate symbol _SRHTTPResponseErrorKey in:
    Shared/Libraries/XXX.framework/XXXSDK(SRWebSocket.o)
    Shared/Libraries/YYY.framework/YYYSDK(YYYSRWebSocket.o)

Is there a way to resolve such errors without altering the framework(s) ?

Bobrovsky
  • 13,789
  • 19
  • 80
  • 130

1 Answers1

2

Problem is that the framework and your code (or another of your frameworks) contains the same classes/frameworks. The developer of the framework thought that making it's own framework an umbrella for the other one is a good idea - it isn't. A framework should never contain another one.

BTW: Thats the reason why every class of your ObjectiveC framework should have a prefix. It lowers the possibilities for a conflict.

There are following solutions for you:

  1. If you add one of the two conflicting classes: Rename the class in your code. Maybe fork the framework and change the prefix of all classes or create a wrapper framework with the technic in 3).

  2. Ask the developer to remove all external code and link it only. In addition he/she has to document the dependency so a user of the framework know which one in which version he/she has to add. You may use a dependency framework like CocoaPods/Carthage or a makefile than to fetch the depending frameworks.

  3. If 2) isn't possible because the framework will be used by other customers and the developer wan't break their code (stupid reason by the way): Ask the developer of the framework to add for each class that isn't his own code an "Other C Flag" like described here

ObjectAlchemist
  • 1,109
  • 1
  • 9
  • 18
  • They probably renamed the classes (see `SRWebSocket` and `YYYSRWebSocket` in the question). They probably missed some constant. However, one missed symbol is enough to cause problems... Probably it would be enough to remove the symbol from the class because it's already included in the framework. – Sulthan Apr 19 '17 at 20:58
  • 1
    By the way, the reason to include the framework inside another framework is done to hide the implementation, for example if your cocoapod contains a static library with your compiled code and frameworks. I believe google analytics are doing that. – Sulthan Apr 19 '17 at 21:06
  • Yes I know there are reasons for this technic, but sooner or later it will make trouble like in this case. I've also had some problems like that with closed source frameworks. It will become really interesting if the contained code uses resources that shouldn't used twice, like bluetooth or network indicator or if it triggers/recieves notifications. Thats the reason why I wrote it's never a good idea. – ObjectAlchemist Apr 19 '17 at 21:16