简体   繁体   中英

Why is Xcode on my M1 Mac trying to build for `iOS Simulator-x86_64`? Why is it not building for an `arm` based simulator?

I have an M1 MacBook Air.

When building for a simulator in Xcode, I am seeing the following warnings and errors:

ld: warning: ignoring file /Users/kon/Library/Developer/Xcode/DerivedData/InvisibleComputersApp-hktlnhvaoskvxkcdhnahydmbodzw/Build/Products/Debug-iphonesimulator/GoogleSignIn.o, building for iOS Simulator-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file /Users/kon/Library/Developer/Xcode/DerivedData/InvisibleComputersApp-hktlnhvaoskvxkcdhnahydmbodzw/Build/Products/Debug-iphonesimulator/AppAuth.o, building for iOS Simulator-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file 
/Users/kon/Library/Developer/Xcode/DerivedData/InvisibleComputersApp-hktlnhvaoskvxkcdhnahydmbodzw/Build/Products/Debug-iphonesimulator/GTMAppAuth.o, building for iOS Simulator-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file /Users/kon/Library/Developer/Xcode/DerivedData/InvisibleComputersApp-hktlnhvaoskvxkcdhnahydmbodzw/Build/Products/Debug-iphonesimulator/AppAuthCore.o, building for iOS Simulator-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file /Users/kon/Library/Developer/Xcode/DerivedData/InvisibleComputersApp-hktlnhvaoskvxkcdhnahydmbodzw/Build/Products/Debug-iphonesimulator/GTMSessionFetcherCore.o, building for iOS Simulator-x86_64 but attempting to link with file built for unknown-arm64
Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_GIDConfiguration", referenced from:
      objc-class-ref in GlobalState.o
  "_OBJC_CLASS_$_GIDSignIn", referenced from:
      objc-class-ref in GoogleAuthService.o
      objc-class-ref in GoogleRefreshTokenService.o
      objc-class-ref in InvisibleComputersAppApp.o
  "_OBJC_CLASS_$_GIDSignInButton", referenced from:
      objc-class-ref in LoginView.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This sounds to me like Xcode is somehow trying to build an x86 binary? Why is it even trying to do that, aren't the simulators arm based on the M1 Macs?

How can I

I spent 3 days on this issue beating my head against the wall. Today, I finally cracked it and understood the problem.

I am working on a highly modular project with ~100 frameworks. When migrating from the X86_64 (Intel) architecture to arm64 (M1) I was always getting this error:

Could not find module 'MyModule' for target 'x86_64-apple-ios-simulator'; found: arm64-apple-ios-simulator, at /my/path/

when building natively on M1.

The reason is that the simulator runs natively on M1 but the simulated app runs still under Intel. That's why the x86_64 architecture was built in the first place.

The two architectures are now beating each other as the simulator is arm64 while the simulated app is X86_64. Removing the arm64 architecture for the pods and project settings fixed the issue and I can build the project entirely on M1 now.

Here are screenshots from the ActivityMonitor. AchieveMe is the app running in the simulator.

在此处输入图像描述 在此处输入图像描述

To fix the problem for Cocoapods you can simply do:

target.build_configurations.each do |config|
  config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64'
end

I am using XcodeGen and there it can simply be added under debug configuration as:

YourSettings
...
configs:
      Debug:
        EXCLUDED_ARCHS[sdk=iphonesimulator*]: arm64

Best of luck, I hope it helps. I can sleep in peace now.

You can try opening Xcode with "Open using Rosetta" check ON.

  1. Quit Xcode
  2. Go to your Applications folder
  3. Right click Xcode then select "Get Info"
  4. Check "Open using Rosetta"
  5. Open Xcode

使用 Rosetta 打开

如果您有一个不支持 arm64 的依赖项,您可以通过将“arm64”添加到目标构建设置中的排除架构列表 ( EXCLUDED_ARCHS ) 中来告诉构建系统跳过 arm64(此构建 x86_64)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM