'Undefined symbols for architecture arm64, it seems just randomly happened to some third party framework using cocoapods

What happened

  1. I used Cocoapods to manage some third-party frameworks
  2. I used some private spec repos
  3. More than one private repos have dependency on same third-party pods
  4. After a modification of dependency structure,I build my workspace, it shows these errors:
Undefined symbols for architecture arm64:
  "_OBJC_METACLASS_$_UIView", referenced from:
      _OBJC_METACLASS_$_iCarousel in iCarousel.o
  "_OBJC_CLASS_$_UIButton", referenced from:
      objc-class-ref in iCarousel.o
  "_OBJC_CLASS_$_UIScrollView", referenced from:
      objc-class-ref in iCarousel.o
  "_OBJC_CLASS_$_UIScreen", referenced from:
      objc-class-ref in iCarousel.o
  "_OBJC_CLASS_$_UITapGestureRecognizer", referenced from:
      objc-class-ref in iCarousel.o
  "_OBJC_CLASS_$_UIView", referenced from:
      objc-class-ref in iCarousel.o
      _OBJC_CLASS_$_iCarousel in iCarousel.o
  "_OBJC_CLASS_$_UIBarButtonItem", referenced from:
      objc-class-ref in iCarousel.o
  "_UITrackingRunLoopMode", referenced from:
      -[iCarousel startAnimation] in iCarousel.o
  "_CGSizeZero", referenced from:
      -[iCarousel setUp] in iCarousel.o
  "_OBJC_CLASS_$_UIPanGestureRecognizer", referenced from:
      objc-class-ref in iCarousel.o
  "_UIAccessibilityTraitAllowsDirectInteraction", referenced from:
      -[iCarousel setUp] in iCarousel.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

What I've done to try to solve this problem?(none of them works)

  1. Deleted Xcode caches by rm -rf ~/Library/Developer/Xcode/DerivedData/
  2. Deleted Cocoapods caches by $ rm -rf "${HOME}/Library/Caches/CocoaPods" $rm -rf "pwd/Pods/" $pod update
  3. Update the Xcode version to 12.0.1

Oh no, same errors!

What I've done next...

I decided to go the hard way, so I add those things to my Podfile:

if target.name == "iCarousel"
  config.build_settings['OTHER_LDFLAGS'] ||= ['$(inherited)']
  config.build_settings['OTHER_LDFLAGS'] << '-framework "UIKit"'
  config.build_settings['OTHER_LDFLAGS'] << '-framework "CoreGraphics"'
end

Then, pod install

Build my project...

Good news! nothing to do with iCarousel! Bad news, same old errors happened to another pod: PomeloPush

Undefined symbols for architecture arm64:
  "_SCNetworkReachabilitySetDispatchQueue", referenced from:
      -[PomeloReachability startNotifier] in PomeloReachability.o
      -[PomeloReachability stopNotifier] in PomeloReachability.o
  "_SCError", referenced from:
      -[PomeloReachability startNotifier] in PomeloReachability.o
  "_SCErrorString", referenced from:
      -[PomeloReachability startNotifier] in PomeloReachability.o
  "_SCNetworkReachabilityGetFlags", referenced from:
      -[PomeloReachability isReachable] in PomeloReachability.o
      -[PomeloReachability isReachableViaWWAN] in PomeloReachability.o
      -[PomeloReachability isReachableViaWiFi] in PomeloReachability.o
      -[PomeloReachability connectionRequired] in PomeloReachability.o
      -[PomeloReachability isConnectionOnDemand] in PomeloReachability.o
      -[PomeloReachability isInterventionRequired] in PomeloReachability.o
      -[PomeloReachability reachabilityFlags] in PomeloReachability.o
      ...
  "_SCNetworkReachabilitySetCallback", referenced from:
      -[PomeloReachability startNotifier] in PomeloReachability.o
      -[PomeloReachability stopNotifier] in PomeloReachability.o
  "_SCNetworkReachabilityCreateWithAddress", referenced from:
      +[PomeloReachability reachabilityWithAddress:] in PomeloReachability.o
  "_CFHostStartInfoResolution", referenced from:
      +[PomeloHostRequest nslookup:] in PomeloHostRequest.o
  "_OBJC_CLASS_$_UIDevice", referenced from:
      objc-class-ref in PomeloClient.o
  "_SCNetworkReachabilityCreateWithName", referenced from:
      +[PomeloReachability reachabilityWithHostname:] in PomeloReachability.o
  "_CFHostCreateWithName", referenced from:
      +[PomeloHostRequest nslookup:] in PomeloHostRequest.o
  "_CFHostGetAddressing", referenced from:
      +[PomeloHostRequest nslookup:] in PomeloHostRequest.o
  "_OBJC_CLASS_$_UIPasteboard", referenced from:
      objc-class-ref in Pomelo_OpenUDID.o
  "_UIApplicationDidEnterBackgroundNotification", referenced from:
      -[PomeloClient addNotification] in PomeloClient.o
  "_UIApplicationWillEnterForegroundNotification", referenced from:
      -[PomeloClient addNotification] in PomeloClient.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Then I added some similar code in Podfile Then pod install, build Oh, a similar error happened to another pod:

Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_UIViewController", referenced from:
      __OBJC_$_CATEGORY_UIViewController_$_KeyboardAnimation in UIViewController+KeyboardAnimation.o
  "_UIKeyboardAnimationDurationUserInfoKey", referenced from:
      -[UIViewController(KeyboardAnimation) getDurationFromNotification:] in UIViewController+KeyboardAnimation.o
  "_UIKeyboardAnimationCurveUserInfoKey", referenced from:
      -[UIViewController(KeyboardAnimation) getAnimationCurveFromNotification:] in UIViewController+KeyboardAnimation.o
  "_UIKeyboardFrameEndUserInfoKey", referenced from:
      -[UIViewController(KeyboardAnimation) getKeyboardRectFromNotification:] in UIViewController+KeyboardAnimation.o
  "_UIKeyboardWillChangeFrameNotification", referenced from:
      -[UIViewController(KeyboardAnimation) an_subscribeKeyboardFrameChangesWithAnimations:] in UIViewController+KeyboardAnimation.o
      -[UIViewController(KeyboardAnimation) an_unsubscribeKeyboardFrameChanges] in UIViewController+KeyboardAnimation.o
  "_UIKeyboardWillShowNotification", referenced from:
      -[UIViewController(KeyboardAnimation) an_subscribeKeyboardWithBeforeAnimations:animations:completion:] in UIViewController+KeyboardAnimation.o
      -[UIViewController(KeyboardAnimation) an_unsubscribeKeyboard] in UIViewController+KeyboardAnimation.o
  "_OBJC_CLASS_$_UIView", referenced from:
      objc-class-ref in UIViewController+KeyboardAnimation.o
  "_UIKeyboardWillHideNotification", referenced from:
      -[UIViewController(KeyboardAnimation) an_subscribeKeyboardWithBeforeAnimations:animations:completion:] in UIViewController+KeyboardAnimation.o
      -[UIViewController(KeyboardAnimation) an_unsubscribeKeyboard] in UIViewController+KeyboardAnimation.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

for now, it had happened on pop, AFNetworking, SDWebImage, iCarousel, MJRefresh, and so on...

Any suggestions could help would be greatly appreciated!! I've stuck on this for a week...



Solution 1:[1]

By looking out your observation you can try out the following suggestion:

  1. Check if your cocoapods are updated to latest version.
  2. remove all pods using pod deintegrate.
  3. check the dependencies of pods and try to install one by one. pod install.
  4. also check the support of libraries to your swift version.
  5. if both libraries have same code or extension it will give you the error.

Solution 2:[2]

Also could be helpful to remove all pods first:

pod deintegrate

then

pod install

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman
Solution 2 nastassia