7

Here is my podFile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '7.0'
pod 'AFNetworking'
pod 'ODSAccordionView', '0.4.4'
pod 'IQKeyboardManager'
pod 'NYXImagesKit', :git => 'https://github.com/Nyx0uf/NYXImagesKit.git'
pod 'PEPhotoCropEditor'
pod 'CocoaAsyncSocket'
pod 'PKRevealController'
pod 'Haneke', '~> 1.0'
pod 'MBProgressHUD', '~> 0.9.1'
pod 'RadioButton'

Everythig has been working fine for a long time, but now, when I update my pods (pod update) these 3 pods get uptated:

  • AFNetworking
  • CocoaAsyncSocket
  • IQKeyboardManager

After that, nothing works anymore.

I get more than 600 duplicate symbols for architecture i386 errors, like this one:

duplicate symbol _OBJC_IVAR_$_AFHTTPRequestOperation._responseSerializer in:
/Users/myuser/Library/Developer/Xcode/DerivedData/MyProject-emjexnnjljambodthokzwpwcddhz/Build/Products/Debug-iphonesimulator/libPods-AFNetworking.a(AFHTTPRequestOperation.o)
/Users/myuser/Library/Developer/Xcode/DerivedData/MyProject-emjexnnjljambodthokzwpwcddhz/Build/Products/Debug-iphonesimulator/libAFNetworking.a(AFHTTPRequestOperation.o)
... (661 times the same error but pointing to different duplicated files)
ld: 661 duplicate symbols for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Any ideas?

EDITED: After doing the solution shown below, my project only compiles for iPad Air and I can not Archive anymore, i still get the same error...

Ale
  • 2,282
  • 5
  • 38
  • 67

6 Answers6

12

I use the 'Manually Rename All of the Symbols' approach. I was experiencing the duplicate symbol _OBJC_METACLASS_$_PodsDummy_Pods and so i added the post_install in the Podfile to avoid the duplicate symbol.

Replace your pod file content with this to 'Manually Rename All of the Symbols'

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '7.0'

post_install do |installer_representation|
    installer_representation.project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = '$(inherited), PodsDummy_Pods=SomeOtherNamePodsDummy_Pods'
        end
    end
end

pod 'AFNetworking'
pod 'ODSAccordionView', '0.4.4'
pod 'IQKeyboardManager'
pod 'NYXImagesKit', :git => 'https://github.com/Nyx0uf/NYXImagesKit.git'
pod 'PEPhotoCropEditor'
pod 'CocoaAsyncSocket'
pod 'PKRevealController'
pod 'Haneke', '~> 1.0'
pod 'MBProgressHUD', '~> 0.9.1'
pod 'RadioButton'

Edited : Delete the following pod item's from your project

1.Pods Folder

2.Podfile.lock

3.ProjectName.xcworkspace

And then install the pods again

This hook allows you to make any last changes to the generated Xcode project before it is written to disk or any other tasks you might want to perform.

Reference -
1. https://developerinsider.co/cocoapods-remove-duplicate-symbols-errors/
2. http://guides.cocoapods.org/syntax/podfile.html#post_install

Vineet Choudhary
  • 7,433
  • 4
  • 45
  • 72
  • I'm getting this error: `[!] An error occurred while processing the post-install hook of the Podfile. undefined method project for #` – Ale Sep 16 '15 at 10:24
  • 1
    delete the following pod item's from your project `1. Pods Folder` `2. Podfile.lock` `3. ProjectName.xcworkspace` And then install the pods again – Vineet Choudhary Sep 16 '15 at 10:27
  • 3
    That was the key! removing the files and installing the pods again. By the way, I also had to change `project` to `pods_project `. Thanks a lot it works now :) – Ale Sep 16 '15 at 10:45
  • Which error?? Error mention in question or error mention in comment?? – Vineet Choudhary Sep 16 '15 at 11:15
  • Sorry, the error mentioned in the question: `duplicate symbols for architecture i386` – Ale Sep 16 '15 at 11:19
  • Please post the full error stack trace, because in my case i'm able to `archive`. – Vineet Choudhary Sep 16 '15 at 11:24
  • Please go in `Project Targets > Build Phase > Link Binary With Libraries` then check the font color of 'libPods.a' libraries. if it's red then delete the `libPods.a` and try to `archive` – Vineet Choudhary Sep 16 '15 at 11:42
  • than try to `master reset.` 1. `delete the derived data` 2. `Clean the project` 3. Repeat the above process i.e delete the following pod item's from your project `1. Pods Folder` `2. Podfile.lock` `3. ProjectName.xcworkspace` And then install the pods again – Vineet Choudhary Sep 16 '15 at 11:48
  • If you still got same error, then delete the 'libPods.a' librarie either it's color red or gray – Vineet Choudhary Sep 16 '15 at 12:00
  • after doing what you said and re-installing my cocoa pods again `sudo gem install cocoapods` everything seems to work fine again. Thank you very much for your help – Ale Sep 16 '15 at 13:32
  • @VineetChoudhary You appear to have taken the first part of your answer from [here](http://stackoverflow.com/questions/21249273/prevent-duplicate-symbols-when-building-static-library-with-cocoapods) without attribution. – trojanfoe Sep 18 '15 at 14:19
  • Also try the answer below, In my case, by combining two answers, I solve the problem. – Randall Wang Jul 27 '17 at 09:58
6

Even after deleting my pods and reinstalling them, I had always the same problem.

I finally found the solution by comparing with another project. The issue was in the parameter "Other Linker Flags" (OTHER_LDFLAGS) in the Build Settings of the project. The pods were referenced not just by their name, but by adding the prefix "Pods-myProject"

"-l\"Pods-myProject-AMSlideMenu\"",
"-l\"Pods-myProject-CocoaLumberjack\"",
"-l\"Pods-myProject-DLAlertView\""

So I just removed the prefix and all was right

"-l\"AMSlideMenu\"",
"-l\"CocoaLumberjack\"",
"-l\"DLAlertView\""
Omaty
  • 425
  • 5
  • 14
5

I fixed a similar error (after a messy Cocoapods upgrade) by simply removing and then re-adding the pods. Backup your project, then run:

pod deintegrate
pod install
Dan G
  • 143
  • 1
  • 6
1

In my case we had a project written in objective C and swift with a custom framework module inside and to solve the symbols duplication problem we had to remove all the flags from Other Linker Flags under Build Settings of the project and the framework module.

Before inside Build Settings:

OTHER_LDFLAGS = ( "$(inherited)", "-ObjC", "-all_load" );

After inside Build Settings:

OTHER_LDFLAGS = "$(inherited)";
Ramon Vasconcelos
  • 1,466
  • 1
  • 21
  • 28
0

I think Cocoapods has a bug where pod source files can be accidentally duplicated.

My project was building fine until after performing one pod update at which point a duplicate symbol error appeared.

After lots of confusion, I finally noticed that a Google pod ended up with two files. In my case, it was GTMOAuth2SignIn.m and GTMOAuth2SignIn 2.m. Hence, the duplicate symbol error.

Note that pods seem to reference files by wildcards indicating all source in a directory should be included. This differs from a classic Xcode project where files are explicitly referenced.

Also, I suspect that performing a pod update during a build process could be what's tripping up Cocoapods. The concurrent access to the same file(s) may cause problems. Just a theory.

Also, this may explain why some "solutions" associated with this problem are to remove/delete referenced pods, then re-add.

Daniel
  • 8,794
  • 4
  • 48
  • 71
0

What worked for me:

  1. Read the error report to identify the repo that supposedly contains duplicate files.
  2. Drag the offending repo to the trash.
  3. re-clone your repo.
  4. set up your repo with correct remote tracking. git remote add <url.git>, or git remote set-url <url.git>

This absolutely worked for me. In my case for some elusive reason, when I ran git pull upstream develop for a local dependency, git would pull in/generate duplicate files from multiple commits.

After following the above steps, the issue went away and git pull upstream develop was no longer pulling from multiple commits at once. Perhaps there was a weird git cache for my repo.

ScottyBlades
  • 12,189
  • 5
  • 77
  • 85