51

I have a project that has a dependency (installed via CocoaPods) using SocketRocket and have imported a static library from HeapAnalytics. Apparently the HeapAnalytics library already uses SocketRocket. I get no errors when compiling, but at runtime receive the following:

Class SRWebSocket is implemented in both [path] and [path].
One of the two will be used. Which one is undefined.

I'm not sure how to handle it because most solutions I've seen require compiling the static library yourself change class names and such, and I don't have access to the source.

Any recommendations?

2
  • I guess you'll have to stop linking against SocketRocket directly and instead rely on the one contained with HeapAnalytics.
    – Droppy
    Jun 1, 2015 at 19:46
  • 8
    How do you stop linking against something that is installed as a dependency of something you setup via CocoaPods?
    – MrGrinst
    Jun 1, 2015 at 20:05

4 Answers 4

70

I wrote that error message!•

Either change the class name or don't link against said library.

How is your project configured? Is there anywhere where you explicitly link against SR? Or is it a product of linking against two static libraries that both already include SR?

If the former, then stop linking against SR directly and just inherit the version that came with the library already using it (warning: make sure it has the right version).

If the latter, then you are going to have to modify one of the libraries.

• Actually, I modified the error. It used to imply that one or the other would be used. But that wasn't really what was going on and the behavior was different across different platforms. Thus, it was changed so that it was far more precise in identifying that the behavior was undefined.

18
  • 1
    Thanks bbum. Unfortunately, this confirms my suspicions that I'm going to have to completely modify one of the libraries.
    – MrGrinst
    Jun 1, 2015 at 20:20
  • 1
    Well the fix was a lot easier than I thought. I guess I thought I needed to do something really complicated but all I had to do was refactor -> rename all occurrences of SRWebSocket and it's accompanying inner classes. The only trouble I can foresee with doing this is that if the non-HeapAnalytics libraries are using a different version of SR, there could be some issues.
    – MrGrinst
    Jun 1, 2015 at 20:30
  • 8
    @bbum how can a project use framework classes which are in another framework that the project is linking? (like you say in your answer this apply to the first situation where project explicitly link against SR) if i dont put the import<framework_name> it wont recognize the framework classes
    – Michael A
    Jul 29, 2015 at 10:23
  • 7
    is there a way to silence this warning?
    – Lena Bru
    Nov 16, 2015 at 12:12
  • 1
    @bbum is there something that can be passed to dyld, maybe via some DYLD env var to let it just pick one?
    – user1971598
    May 26, 2016 at 1:57
5

In my case this error appeared when I unnecessarily added a source file to both my main app target and my test target:

Target Membership with both targets selected

Removing the test target from Target Membership solved it:

Target Membership with only one target selected

4

Overview:

The error suggests that the same symbol / class is defined twice.

Solution:

  • Check the frameworks linked to see if there are any duplicates. If so remove the duplicate
  • Clean build folder (Command + Shift + K)
  • If simulator, then reset the simulator and try
  • If device, restart the device and try

My experience:

I faced the same issue twice, once it was duplicate frameworks and the other time resetting simulator helped.

1
  • In my case it was under Dependencies that I had the duplicate, which then fixed the issue for me.
    – totiDev
    Mar 17, 2020 at 8:42
2

I had this warning for more than a month, then I finally tried this and it worked for me:

  1. Reset the simulator (Menu: Hardware -> Erase all content and settings ... )
  2. Clean the project (Command + Shift + K)
  3. Clean the build folder (Command + Option + Shift + K)
  4. Run the code on the simulator again
1
  • 1
    In my case, the above, less the reset. A simple cmd-K on the simulator was sufficient (as i had a few other dev apps that had setups I did not want to lose).
    – drew..
    Nov 22, 2018 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.