Cocoapods remove duplicate symbols for architecture i386 error

When we used two or more 3rd party library in our project using Cocoapods then there are possibility of duplicate symbols used by different libraries. In my case, I just added some pod and after nothing works anymore. I get more than 482 duplicate symbols for architecture i386 errors, like this one:

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

Reason of this error

The main reason of duplicate symbols error is const and extern variable used by one library similar to other library.

Solution

Best solution to remove the duplicate symbols error is, post_install Hook.

The Podfile provides hooks that will be called during the installation process. Hooks are global and not stored per target definition.

post_install Hook - 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. So, to avoid the duplicate symbol I added the post_install in the Podfile

Add post_install in your PodFile just after platform :ios, '8.0' line, to manually rename all of the symbols

platform :ios, '8.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

Delete the following pod item's from your project
1.Pods Folder
2.Podfile.lock
3.ProjectName.xcworkspace

And then install the pods again using pod install command.



Related Article