iOS

Fixing the 'Linking Object File for Architecture arm64' Error in Xcode with CocoaPods


While working on an iOS application in Xcode, you could face this problem:

error in CocoaPods

 

 

The mentioned problem arises from the fact that some of the libraries/frameworks are not yet available for use on Apple Silicon Macs due to incompatibility with the arm64 simulator architecture.

Solution

Exclude arm64 for Simulator Architecture To resolve this, the project will need to delete the arm64 architecture and its CocoaPods dependencies from the iOS simulator support.

1. Exclude arm64 in Your Project's Build Settings

  1. Open your project in Xcode.
  2. Go to Build Settings.
  3. Locate the section called Excluded Architectures.
  4. Add arm64 to the SDK for every iOS simulator.

2. Exclude arm64 in CocoaPods

 

A. Using Custom .xcconfig Files:

If you're managing build configurations with those .xcconfig files, put in the line:

EXCLUDED_ARCHS [sdk=iphonesimulator*] = arm64

this exclusion works during the building session for the Simulator.

 

B. Add Exclusion for Pod Project:

The CocoaPods generated project also needs to exclude the arm64 architecture for the iOS Simulator. However, modifying the Pod project's settings manually is not recommended because the changes will be overwritten the next time you run pod install. Instead, automate the process with a post_install script.

Add the following snippet in your Podfile: 

post_install do |installer| installer.pods_project.build_configurations.each do |config| config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64" endend

This will ensure the exclusion is implemented automatically to all pods on the next installation with pod install.

 

3. Update Podspec for Libraries (Optional):

s.pod_target_xcconfig = { 'EXCLUDED_ARCHS [sdk=iphonesimulator*]''arm64' }s.user_target_xcconfig = { 'EXCLUDED_ARCHS [sdk=iphonesimulator*]' => 'arm64'} For libraries owned or controlled by you, the Podspec file may be modified to conform to the following lines:

Why Is arm64 Excluded?

This all happened because the precompiled libraries do not match with the architecture requirements of the Simulator. As a result as follows, 

  • Xcode will use the x86_64 architecture for the Simulator because there are no compatibility issues.

  •  Build for physical devices that are unaffected by arm64.

     

Conclusion

By excluding the arm64 architecture for the Simulator at both the project and CocoaPod levels, one can solve "linking object file for architecture 'arm64'" error. The post install script provided in the Podfile allows for seamless setup without manual intervention for future pod install runs.

Thus, it will ensure that your application builds properly on both Apple Silicon and Intel Macs during development.

Ready to transform your business with our technology solutions? Contact Us  today to Leverage Our iOS Expertise.

0

iOS

Related Center Of Excellence