Yuchen
Yuchen

Reputation: 33116

duplicate symbol while adding a static library to a Xcode project

I am trying to add this photo browser library to our project. I am following Method 2: Static Library in the readme.md file. Basically, it is very standard steps for adding static libraries in Xcode. Things work out fine if I create a simple hello world project. However, when I add the library to our existing project, we get the following duplicate symbol error.

Here is an example of the error (there are a lot more but they all looks similar):

duplicate symbol _OBJC_CLASS_$_MBBarProgressView in:
    /Users/.../Build/Intermediates/PDFMaps.build/Debug-iphonesimulator/Project Name.build/Objects-normal/x86_64/MBProgressHUD.o
    /Users/.../Build/Products/Debug-iphonesimulator/libMWPhotoBrowser.a(MBProgressHUD.o)
duplicate symbol _OBJC_METACLASS_$_MBBarProgressView in:
    /Users/.../Build/Intermediates/PDFMaps.build/Debug-iphonesimulator/Project Name.build/Objects-normal/x86_64/MBProgressHUD.o
    /Users/.../Build/Products/Debug-iphonesimulator/libMWPhotoBrowser.a(MBProgressHUD.o)

It seems that duplications always occur between the Intermediates folder and the Products folder. Could anyone explain why is this happening and how to resolve this issue?

Upvotes: 0

Views: 536

Answers (2)

hv88
hv88

Reputation: 328

From the logs it looks like the MWPhotoBrowser library has a class with name MBProgressHUD https://github.com/mwaterfall/MWPhotoBrowser/tree/master/MWPhotoBrowser/Libraries/MBProgressHUD

and also another target in your project hierarchy PDFMaps also has the same name class causing the duplicate symbol error.

Fix is to either rename either one of the classes or reuse MBProgressHUD, whatever works out for you.

Upvotes: 2

Jesse Bunch
Jesse Bunch

Reputation: 6679

I usually see this when one of two things happen:

  • I've added the header and/or implementation to my project twice
  • You have a bad merge in your xcodeproj file that has the symbol showing up more than once.

Here's what I typically do:

  1. Close Xcode. Open up the xcodeproj in a text editor
  2. Remove all traces of your something.h and something.m files
  3. Save and reopen Xcode
  4. Re-add your header and implementation, checking the applicable targets
  5. Build

Upvotes: 0

Related Questions