tags:

views:

758

answers:

5

My project was working fine the whole time, today I added an admob library to my project and now it won't compile!

Here is the error:

ld: duplicate symbol .objc_category_name_NSCharacterSet_NSCharacterSet_Extensions in /Photo/libAdMobSimulator.a(NSCharacterSet_Extensions.o) and /Photo/build/Photo.build/Debug-iphonesimulator/Photo.build/Objects-normal/i386/NSCharacterSet_Extensions.o

How to fix?

+1  A: 

You have a category NSCharacterSet_Extensions on NSCharacterSet defined in both libAdMobSimulator and in your code in the Photo (app/bundle)

You need to make sure the category name is unique ie rename one of these categories.

Mark
A: 

Did you use #include for a header file instead of #import? I'm not sure it would apply in this case, but that is one way to get duplicate symbols.

Amagrammer
+2  A: 

just as a follow up note: i got this error as I had included the popular touchjson library. the admob library comes with its own copy, and this is what caused the clash for me. remove your copy of the touchjson library from your project and you are good to go.

jdee
A: 

I once got this error when I made the dumb mistake of switching my .h and .m files up in a category that I had made. Hope this helps someone from doing the same :)

Reed Olsen
+2  A: 

I had the same problem, for the same reason, looked all over and this was the fix.

ObjC and -all_load need to be in the TARGET's "Other Linker Flags." If you've got the same problem, you'll know it because while the categories are now successfully linked, your app won't build because of some "duplicate symbols."

Dang.

But wait - as jdee points out:

i got this error as I had included the popular touchjson library. the admob library comes with its own copy

And deleting the copy of TouchJSON you included does indeed clear up the issue.

Still... this isn't ideal. I'm pretty sure the version of TouchJSON in there is good, but I'd really like to be able to update in the future.

This guy found another solution, but it involves renaming everything you use from TouchJSON. Not ideal.

I'm at a loss, right now, but luckily not at a loss for the quick fix. Still, it would be nice to hear from one of you monster brains out there how you would avoid running into this kind of conflict if you were the developer of a popular static library.

I'm starting up another question on that subject. See if we can get some sense around these parts.

UPDATE:

Leave the header files from your copy of TouchJSON in your project. Remove the implementation files, then you won't create any object files, then you won't create any conflicts. Thanks to this post about a similar conflict involving cocos2d for the final hint on this one.

beOn