Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class is implemented in both. One of the two will be used

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?

like image 229
MrGrinst Avatar asked Jun 01 '15 19:06

MrGrinst


4 Answers

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.

like image 56
bbum Avatar answered Nov 18 '22 15:11

bbum


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

like image 40
Goodsquirrel Avatar answered Nov 18 '22 14:11

Goodsquirrel


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.

like image 3
user1046037 Avatar answered Nov 18 '22 13:11

user1046037


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
like image 2
LukeSideWalker Avatar answered Nov 18 '22 15:11

LukeSideWalker