swift 为什么我的M1 Mac上的Xcode要为'iOS Simulator-x86_64'构建?为什么它不为基于'arm'的模拟器构建?

ycggw6v2  于 2023-01-19  发布在  Swift
关注(0)|答案(3)|浏览(700)

我有一台M1 MacBook Air。
在Xcode中构建模拟器时,我看到以下警告和错误:

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)

这听起来像是Xcode试图构建一个x86二进制代码?为什么它要这么做,模拟器arm不是基于M1 Mac的吗?
我怎么能

nx7onnlm

nx7onnlm1#

我花了3天的时间在这个问题上把头往墙上撞,今天,我终于破解了它,明白了问题所在。
我正在做一个高度模块化的项目,有大约100个框架。当从X86_64(Intel)架构迁移到arm64(M1)时,我总是得到这个错误:

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

在M1上原生构建时。
原因是模拟器在M1上运行,但模拟的应用程序仍然在Intel下运行,这就是为什么最初构建x86_64架构的原因。
这两个架构现在相互竞争,因为模拟器是arm64,而模拟的应用程序是X86_64。删除pod和项目设置的arm64架构解决了这个问题,现在我可以完全在M1上构建项目。
这是ActivityMonitor的截图。AchieveMe是在模拟器中运行的应用程序。
第一节第一节第一节第一节第一次
要解决Cocoapods的问题,只需执行以下操作:

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

我使用的是XcodeGen,可以简单地将其添加到调试配置下,如下所示:

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

祝你好运,希望能有所帮助,我现在可以安心睡觉了。

vjhs03f7

vjhs03f72#

您可以尝试打开Xcode并勾选"使用Rosetta打开"。
1.退出Xcode
1.转到应用程序文件夹
1.右键单击Xcode,然后选择"获取信息"
1.选中"使用Rosetta打开"
1.开放Xcode

pbpqsu0x

pbpqsu0x3#

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

相关问题