Conflict between class and static library

2019-09-17 14:27发布

问题:

I'm using Layar Player in my app.
It provides a static library to include in your project.
After installing and trying to compile, I got this error:

ld: duplicate symbol _OBJC_CLASS_$_Reachability in //LayarPlayer/Debug/liblayarplayer.a(Reachability.o) and //MyApp.build/Debug-iphoneos/MyApp.build/Objects-normal/armv7/Reachability.o for architecture armv7

I'm using Reachability in my app to check network status, but it seems like it's already included in the library.
I've tried removing every #import Reachability in my code, but obviously I get "undeclared function" errors.
How can I solve this?

回答1:

You need to delete the references from the project. That means don't delete the #import Reachability but search for Reachability.m and Reachability.h in your project files and delete them so you only have one of each in your project.



回答2:

I excluded all conflicting .m files from the target and everything is fine now.
Headers files must not be deleted.



回答3:

I solved this same problem by

  1. check your project remove duplicate Reachability file;
  2. replacing old version of Reachability(I'm currently using version 2.2);
  3. put the -ObjC -all_load linker flags on.

Hope it may help.