When I try to integrate a framework into an iOS app, then building will fail on an M1 MacBook (i.e., Apple Silicon), but does not fail on an Intel Mac. This occurs with the default build settings on the latest Xcode and also the latest Xcode Beta.
The error is as follows:
ld: building for iOS Simulator, but linking in object file built for iOS, file '/.../testm1/GooglePlaces.framework/GooglePlaces' for architecture arm64
clang: error: linker command failed with exit code 1 (use - v to see invocation)
I tried to check which architectures are included in the framework, then I am presented with the following info:
Command:
lipo -info GooglePlaces.framework/GooglePlaces
Output:
GooglePlaces.framework/GooglePlaces: Mach-O universal binary with 2 architectures: [x86_64cMach-O 64-bit object x86_64] [arm64]
GooglePlaces.framework/GooglePlaces (for architecture x86_64): Mach-O 64-bit object x86_64
GooglePlaces.framework/GooglePlaces (for architecture arm64): Mach-O 64-bit object arm64
and I also tried to check with ‘file’:
Command:
file GooglePlaces.framework/GooglePlaces
Output:
GooglePlaces.framework/GooglePlaces: Mach-O universal binary with 2 architectures: [x86_64cMach-O 64-bit object x86_64] [arm64]
GooglePlaces.framework/GooglePlaces (for architecture x86_64): Mach-O 64-bit object x86_64
GooglePlaces.framework/GooglePlaces (for architecture arm64): Mach-O 64-bit object arm64
Both commands show that it contains arm64.
Configuration:
MacBook Pro. 13” M1 2020,
16 GB
Big Sur 11.4
Xcode 12.5.1 & Xcode 13.0 (Beta 3)
Steps to reproduce:
- Create a new project (select SwiftUI)
- Integrate the GooglePlaces framework (as described in "Manually" here –> https://developers.google.com/maps/documentation/places/ios-sdk/start)
- Import "GooglePlaces" in a file
- try to build the project on an M1 Mac (Config 1)
- observe the following error:
ld: building for iOS Simulator, but linking in object file built for iOS, file '/.../testm1/GooglePlaces.framework/GooglePlaces' for architecture arm64
clang: error: linker command failed with exit code 1 (use - v to see invocation)
Questions:
- Is this resolvable if I do not have control over the sources of the framework, just the built framework?
- How can I check, given the .framework file, if the framework supports arm64 for iphonesimulator, or only supports arm64 for iphoneos?
As suggested:
I excluded the arm64 for any ios simulators – then building is successful.
BUT: When I want to test the project without a host application the following error occurs:
2021-07-21 12:07:54.021519+0200 xctest[84732:517962] The bundle “testm1Tests” couldn’t be loaded because it doesn’t contain a version for the current architecture. Try installing a universal version of the bundle.
2021-07-21 12:07:54.021692+0200 xctest[84732:517962] (dlopen_preflight(/.../Build/Products/Debug-iphonesimulator/testm1Tests.xctest/testm1Tests): no suitable image found. Did find:
/.../Library/Developer/Xcode/DerivedData/testm1-bkwdzlmojcaocfabaqfrhjnlzfim/Build/Products/Debug-iphonesimulator/testm1Tests.xctest/testm1Tests: mach-o, but wrong architecture)
Program ended with exit code: 80
A workaround option:
- As not all frameworks support xcframeworks, launch Xcode with
Rosetta
. Then you will have no issues with any of those erros. I know that’s not the best workaround as Apple may removeRosetta
in future MacOS releases.
2
Answers
In your project go to the
Since you have specifically mentioned you are trying to build Google Places on M1 Mac, this is not possible was of now since GooglePlaces has not been updated to the new XCFrameworks,
Even you can check out the open issue here:
https://github.com/googlemaps/google-maps-ios-utils/issues/355
Moreover for any frameworks to be run on M1 Mac simulator they should be shipped as XCFramework or you could as of now run on a physical device
Or apart from Google Places, for other frameworks you could use Carthage to consume them as xcframework by the use of below commnand: