最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[基本解决]使用iOS模拟器iPhone 6结果编译出错:file was built for i386 which is not the architecture being linked x86_64

Xcode crifan 11834浏览 0评论

[背景]

之前用iOS 模拟器的iPhone 5,去编译和测试程序,是好好的

但是切换到iPhone 6(9.3)之后,就出错了:

file was built for i386 which is not the architecture being linked x86_64

 

Ld /Users/crifan/Library/Developer/Xcode/DerivedData/QorosSales-fdvmkfwiibblhkeaqjznadykdyuj/Build/Products/Debug-iphonesimulator/QorosSales.app/QorosSales normal x86_64

    cd /Users/crifan/dev/dev_root/daryun/Projects/Qoros/QorosSales/Sourcecode/QorosSales

    export IPHONEOS_DEPLOYMENT_TARGET=8.0

    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"

    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk -L/Users/crifan/Library/Developer/Xcode/DerivedData/QorosSales-fdvmkfwiibblhkeaqjznadykdyuj/Build/Products/Debug-iphonesimulator -F/Users/crifan/Library/Developer/Xcode/DerivedData/QorosSales-fdvmkfwiibblhkeaqjznadykdyuj/Build/Products/Debug-iphonesimulator -F/Users/crifan/Library/Developer/Xcode/DerivedData/QorosSales-fdvmkfwiibblhkeaqjznadykdyuj/Build/Products/Debug-iphonesimulator/DBGuestureLock -F/Users/crifan/Library/Developer/Xcode/DerivedData/QorosSales-fdvmkfwiibblhkeaqjznadykdyuj/Build/Products/Debug-iphonesimulator/KKGestureLockView -F/Users/crifan/Library/Developer/Xcode/DerivedData/QorosSales-fdvmkfwiibblhkeaqjznadykdyuj/Build/Products/Debug-iphonesimulator/SEFilterControl -F/Users/crifan/dev/dev_root/daryun/Projects/Qoros/QorosSales/Sourcecode/QorosSales/Carthage/Build/iOS -filelist /Users/crifan/Library/Developer/Xcode/DerivedData/QorosSales-fdvmkfwiibblhkeaqjznadykdyuj/Build/Intermediates/QorosSales.build/Debug-iphonesimulator/QorosSales.build/Objects-normal/x86_64/QorosSales.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -Xlinker -rpath -Xlinker @loader_path/Frameworks -Xlinker -rpath -Xlinker @executable_path/Frameworks -mios-simulator-version-min=8.0 -Xlinker -no_deduplicate -Xlinker -objc_abi_version -Xlinker 2 -framework DBGuestureLock -framework KKGestureLockView -framework SEFilterControl -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -Xlinker -add_ast_path -Xlinker /Users/crifan/Library/Developer/Xcode/DerivedData/QorosSales-fdvmkfwiibblhkeaqjznadykdyuj/Build/Intermediates/QorosSales.build/Debug-iphonesimulator/QorosSales.build/Objects-normal/x86_64/QorosSales.swiftmodule -framework Alamofire -framework SwiftKeychainWrapper -framework Charts -framework Realm -framework RealmSwift -framework Cartography -framework XCGLogger -framework Pods_QorosSales -Xlinker -dependency_info -Xlinker /Users/crifan/Library/Developer/Xcode/DerivedData/QorosSales-fdvmkfwiibblhkeaqjznadykdyuj/Build/Intermediates/QorosSales.build/Debug-iphonesimulator/QorosSales.build/Objects-normal/x86_64/QorosSales_dependency_info.dat -o /Users/crifan/Library/Developer/Xcode/DerivedData/QorosSales-fdvmkfwiibblhkeaqjznadykdyuj/Build/Products/Debug-iphonesimulator/QorosSales.app/QorosSales

ld: warning: ignoring file /Users/crifan/Library/Developer/Xcode/DerivedData/QorosSales-fdvmkfwiibblhkeaqjznadykdyuj/Build/Products/Debug-iphonesimulator/Charts.framework/Charts, file was built for i386 which is not the architecture being linked (x86_64): /Users/crifan/Library/Developer/Xcode/DerivedData/QorosSales-fdvmkfwiibblhkeaqjznadykdyuj/Build/Products/Debug-iphonesimulator/Charts.framework/Charts

Undefined symbols for architecture x86_64:

  "Charts.LineChartData.__allocating_init (xVals : [__ObjC.NSObject]?, dataSets : [Charts.IChartDataSet]?) -> Charts.LineChartData", referenced from:

      QorosSales.setDoubleLineChart (Charts.LineChartView, xPoints : [Swift.String], leftAxisValues : [Swift.Double], rightAxisValues : [Swift.Double], leftAxisLabel : Swift.String, rightAxisLabel : Swift.String, leftColor : __ObjC.UIColor, rightColor : __ObjC.UIColor) -> () in CrifanLib.o

  "Charts.ChartDataEntry.__allocating_init (value : Swift.Double, xIndex : Swift.Int) -> Charts.ChartDataEntry", referenced from:

      QorosSales.setSingleLineChart (Charts.LineChartView, xPointList : [Swift.String], leftYAXisValues : [Swift.Double], leftYAxisLabel : Swift.String, lineColor : __ObjC.UIColor) -> () in CrifanLib.o

。。。。。。。。。。

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

 

但是是可以运行在iPhone 6(9.3)的真机上面的

 

搜:

Undefined symbols for architecture x86_64 Charts.LineChartData

 

xcode Undefined symbols for architecture x86_64 Charts.LineChartData

 

ios – Undefined symbols for architecture x86_64 on Xcode 6.1 – Stack Overflow

objective c – Xcode build failure "Undefined symbols for architecture x86_64" – Stack Overflow

 

其中,此处出问题的Charts库,记得是:

用Carthage去直接下载已编译好的二进制framework文件的

 

看到:

ld: warning: ignoring file /Users/crifan/Library/Developer/Xcode/DerivedData/QorosSales-fdvmkfwiibblhkeaqjznadykdyuj/Build/Products/Debug-iphonesimulator/Charts.framework/Charts, file was built for i386 which is not the architecture being linked (x86_64

 

-》

猜测是:

Charts库自己编译的时候,是x86(i386)的环境

编译出来的库只有x86的

而我此处的iOS模拟器的iPhone6所在的Mac是x64(x86_64)的

所以没法用

-》好像去重新下载Charts源码并编译,估计就解决问题了?

-》但是为何此处的iOS模拟器的iPhone 5,可以正常运行呢???

Fix for "undefined symbols" when building in Xcode 6 – x-code – openFrameworks

Undefined symbols for architecture x86_64 (command line app) · Issue #2324 · AFNetworking/AFNetworking

ios – Undefined symbols for architecture x86_64 on Xcode 6.1 – Stack Overflow

此处,也去项目的targets中看到了architectures是x64的:

 

architectures standard architectures armv7 arm64 ARCHS_STANDARD

 

而没有包含x86==i386

所以,不要去乱改为i386

-》可能会导致其他库有问题了

-》保险起见,还是去下载Charts的源码并编译吧

carthage update –no-use-binaries Charts

 

licrifandeMacBook-Pro:QorosSales crifan$ carthage update –no-use-binaries Charts
*** Fetching SwiftKeychainWrapper
*** Fetching Alamofire
*** Fetching XCGLogger
*** Fetching realm-cocoa
*** Fetching Charts
*** Fetching Cartography
*** Checking out Charts at "v2.2.4"
*** xcodebuild output can be found in /var/folders/46/2hjxz38n22n3ypp_5f6_p__00000gn/T/carthage-xcodebuild.CNRmP0.log
*** Building scheme "Charts-OSX" in Charts.xcodeproj
*** Building scheme "Charts-TV" in Charts.xcodeproj
*** Building scheme "Charts-iOS" in Charts.xcodeproj
*** Building scheme "ChartsRealm-OSX" in ChartsRealm.xcodeproj
*** Building scheme "ChartsRealm-TV" in ChartsRealm.xcodeproj
** BUILD FAILED **
The following build commands failed:
Ld /Users/crifan/Library/Developer/Xcode/DerivedData/ChartsRealm-henokosypuekvqgqvthggjdtnuey/Build/Products/Release-appletvos/Charts.framework/Charts normal arm64
(1 failure)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
A shell task (/usr/bin/xcrun xcodebuild -project /Users/crifan/dev/dev_root/daryun/Projects/Qoros/QorosSales/Sourcecode/QorosSales/Carthage/Checkouts/Charts/ChartsRealm/ChartsRealm.xcodeproj -scheme ChartsRealm-TV -configuration Release -sdk appletvos ONLY_ACTIVE_ARCH=NO BITCODE_GENERATION_MODE=bitcode CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES clean build) failed with exit code 65:
** BUILD FAILED **
The following build commands failed:
Ld /Users/crifan/Library/Developer/Xcode/DerivedData/ChartsRealm-henokosypuekvqgqvthggjdtnuey/Build/Products/Release-appletvos/Charts.framework/Charts normal arm64
(1 failure)

 

除了暂时用不到到tvOS的Charts库,其他都正常编译了

去看对应的iOS的Charts.framework,也是最新刚刚编译出来的:

 

build ios charts framework file

 

 

再去重新编译项目试试

问题依旧。

换不同iOS模拟器试试:

iPhone 6 (9.3)

iPhone 6 (8.1)

iPhone 5s (9.3)

iPhone 5s (8.1)

iPhone 6 Plus (8.1)

iPhone 6s

都会出现同样错误

但是:

iPhone 5 (9.3)

iPhone 5 (8.1)

都没问题,都可以正常编译,链接库,运行

搜:

xcode iphone 6 simulator file was built for i386 which is not the architecture being linked (x86_64)

cocoa – Xcode 6.1: file was built for x86_64 which is not the architecture being linked (i386) – Stack Overflow

ios – Xcode error: file was built for archive which is not the architecture being linked (x86_64) – Stack Overflow

framework search paths inherited project_dir carthage build ios

 

$(inherited)

$(PROJECT_DIR)/Carthage/Build/iOS

清空:

 

clear debug for framework search paths debug

 

再去试试

结果不行,找不到库:

no such module carthography

 

改回去.

 

结果找不到我另外的用cocoapods管理的库了

所以还是要加上:$(inherited)

 

结果问题依旧:

 

-》

感觉是:

即使是从Charts的源码去编译,但是由于Charts提供的scheme中制定了x86而不是x86_64

所以即使重新编译也没用。。。

但是最诡异的还是:

为何iPhone 5可以

之后的6 6s 6sp都不可以?

算了,还是把Charts的管理从Carthage换成Cocoadpods试试

Cartfile变成:

github "robb/Cartography"

github "realm/realm-cocoa"

github "DaveWoodCom/XCGLogger" ~> 3.3

github "Alamofire/Alamofire" ~> 3.4

github "jrendel/SwiftKeychainWrapper"

Podfile变成:

# Uncomment this line to define a global platform for your project

platform :ios, ‘8.0’

# Uncomment this line if you’re using Swift

use_frameworks!

target ‘QorosSales’ do

    pod ‘Charts’

    pod "KKGestureLockView"

    pod ‘SEFilterControl’

end

target ‘QorosSalesTests’ do

end

target ‘QorosSalesUITests’ do

end

去更新:

licrifandeMacBook-Pro:QorosSales crifan$ carthage update
*** Fetching SwiftKeychainWrapper
*** Fetching Alamofire
*** Fetching XCGLogger
*** Fetching realm-cocoa
*** Fetching Cartography
*** Checking out Alamofire at "3.4.0"
*** Checking out SwiftKeychainWrapper at "1.0.11"
*** Checking out XCGLogger at "Version_3.3"
*** Downloading realm-cocoa.framework binary at "v0.103.0"
*** Checking out Cartography at "0.6.0"
*** xcodebuild output can be found in /var/folders/46/2hjxz38n22n3ypp_5f6_p__00000gn/T/carthage-xcodebuild.jn8klX.log
*** Building scheme "Alamofire watchOS" in Alamofire.xcworkspace
*** Building scheme "Alamofire iOS" in Alamofire.xcworkspace
*** Building scheme "Alamofire OSX" in Alamofire.xcworkspace
*** Building scheme "Alamofire tvOS" in Alamofire.xcworkspace
*** Building scheme "Cartography-iOS" in Cartography.xcodeproj
*** Building scheme "Cartography-Mac" in Cartography.xcodeproj
*** Building scheme "SwiftKeychainWrapper" in SwiftKeychainWrapper.xcodeproj
*** Building scheme "XCGLogger (OS X)" in XCGLogger.xcodeproj
*** Building scheme "XCGLogger (tvOS)" in XCGLogger.xcodeproj
*** Building scheme "XCGLogger (watchOS)" in XCGLogger.xcodeproj
*** Building scheme "XCGLogger (iOS)" in XCGLogger.xcodeproj
/Users/crifan/dev/dev_root/daryun/Projects/Qoros/QorosSales/Sourcecode/QorosSales/Carthage/Checkouts/Cartography/Cartography/ViewUtils.swift:40:16: warning: 'anyGenerator' is deprecated: renamed to 'AnyGenerator'
 。。。。。。
licrifandeMacBook-Pro:QorosSales crifan$ pod install
Analyzing dependencies
Downloading dependencies
Installing Charts (2.2.4)
Using KKGestureLockView (1.0.0)
Using SEFilterControl (2.0.0)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There are 3 dependencies from the Podfile and 3 total pods installed.

结果错误依旧。。

去删除掉,Carthage的Build/iOS中残留的Charts的库:Charts.framework

错误依旧。。。

 

把:

Build Active Architecture Only-》Debug的Yes改为No

change debug from yes to no under build active architecture only

 

结果导致额外的警告:

【已解决】Xcode编译警告:Target of project Pods was rejected as an implicit dependency for because its architectures x86_64 didn’t contain all required architectures i386 x86_64

 

无意间看到:

ld: warning: ignoring file /Users/crifan/Library/Developer/Xcode/DerivedData/QorosSales-fdvmkfwiibblhkeaqjznadykdyuj/Build/Products/Debug-iphonesimulator/Charts.framework/Charts, file was built for i386 which is not the architecture being linked (x86_64): /Users/crifan/Library/Developer/Xcode/DerivedData/QorosSales-fdvmkfwiibblhkeaqjznadykdyuj/Build/Products/Debug-iphonesimulator/Charts.framework/Charts

中提到了:

Xcode/DerivedData

 

也无意间看到了Xcode的设置中,有个Xcode/DerivedData,所以去看看:

xcode preferences locations derived data default

 

deriveddata project build products

 

看到这里的Chart.framework是i386的:

charts.framework modules charts.swiftmodule is i386

而这里

Charts charts.framework modules charts.swiftmodule is x86_64

x86_64

 

算了,去删除掉:

/Users/crifan/Library/Developer/Xcode/DerivedData/QorosSales-fdvmkfwiibblhkeaqjznadykdyuj/Build/Products/Debug-iphonesimulator/

下面的:

Charts.framework

-》希望xcode可以自动找到另外的:

Charts/Charts.framework

 

之所以能够想到去删除那个:

Build/Products/Debug-iphonesimulator/

下面的

Charts.framework

是因为:

Podfile中的:

target ‘QorosSales’ do

    pod ‘Charts’

    pod "KKGestureLockView"

    pod ‘SEFilterControl’

end

包括Charts,以及其他几个库:

SEFilterControl

KKGestureLockView

对应的xxx.framework都是放在对应的库名字命名的文件夹下的

只有这个Charts.framework是直接放在Debug-iphonesimulator/下面的

 

所以觉得,这个Debug-iphonesimulator下面的Charts.framework

应该是之前残留下来的(i386版本的)库,

所以去尝试删除掉

 

然后果然可以正常编译了:

并正常运行了:

finally can build ok and run app on iPhone6 iOS 8.1 12B411

 

同理,其他iPhone 6之后的版本,也都可以运行了。

 

另外,注意到:

/Users/crifan/Library/Developer/Xcode/DerivedData/QorosSales-fdvmkfwiibblhkeaqjznadykdyuj/Build/Products/Debug-iphonesimulator/

下面,还残留一个文件夹:

DBGuestureLock

 

这个也是:

之前用Cocoapods安装的

之后又不用了,虽然cocoapods删除了对应的库

但是Xcode的DerivedData:

/Users/crifan/Library/Developer/Xcode/DerivedData/QorosSales-fdvmkfwiibblhkeaqjznadykdyuj/Build/Products/Debug-iphonesimulator/

中却还残留了对应的文件夹

不过幸好是空的,没啥内容。

 

另外,看到了:

/Users/crifan/Library/Developer/Xcode/DerivedData/QorosSales-fdvmkfwiibblhkeaqjznadykdyuj/Build/Products/Debug-iphoneos/Charts.framework

即,对于iOS的真机,比如我此处的iPhone6的话,用的则是此处的Debug-iphoneos/Charts.framework

是arm64的

-》

所以在iPhone 6真机上是可以正常运行的

 



此处,就可以去尝试,换用Carthage去管理试试了


从podfile中删除掉Charts,然后去:
licrifandeMacBook-Pro:QorosSales crifan$ pod install
Analyzing dependencies
Removing Charts
Downloading dependencies
Using KKGestureLockView (1.0.0)
Using SEFilterControl (2.0.0)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed.



再去Cartfile中加上:
 
github "danielgindi/Charts" ~> 2.2.4
 



去更新:
carthage update –no-use-binaries Charts
结果:

[未解决]Carthage去安装Charts库时编译ChartsRealm-iOS出错:Ld armv7/Charts normal armv7



暂时先不去管Reaml的Charts编译出错了
先用iOS的Charts:
这里新编译出来的Charts.framework,可以看到,是各种架构都支持了:
i386,x86_64,arm,arm64
 
compiled out charts framework include i386 x86_64 arm arm64

 
然后加入到目标的库中:

add charts.framework to targets general linked frameworks and libraries

add run script for charts.framework

 



[总结]
此处,
现象是:
iOS的模拟器,如果是iPhone 5,不论iOS版本是8.1还是最新的9.3,都可以正常使用(不论是Cocoapods还是Carthage去管理的)Charts库
如果是iPhone 6真机,也是可以正常运行的。
但是iOS模拟器换成iPhone 6及其更新的设备(6s,6p,6sp)的话,不论是什么iOS版本8.1还是9.3,始终都无法正常编译
即使是项目的clean后重新build,都还是会在最后的链接的时候出错:
 
ld: warning: ignoring file /Users/crifan/Library/Developer/Xcode/DerivedData/QorosSales-fdvmkfwiibblhkeaqjznadykdyuj/Build/Products/Debug-iphonesimulator/Charts.framework/Charts, file was built for i386 which is not the architecture being linked (x86_64)
 



问题根本原因是:
经过一番折腾,基本上确定原因是:
对于之前使用Cocoapods(或者是Carthage)管理的库:
Charts
虽然删除了(从github上下载下来的,作者提供的已经编译好的二进制的framework文件):
但是Xcode的DerivedData中却仍然残留了旧的针对于i386(x86)平台编译出来的framework文件
/Users/crifan/Library/Developer/Xcode/DerivedData/QorosSales-fdvmkfwiibblhkeaqjznadykdyuj/Build/Products/Debug-iphonesimulator/Charts.framework

 
 

而重新编译Charts库后,实际上已经生成了对应的,我们所需要的,针对于当前x64(x86_64)平台的所需要的库文件了:
/Users/crifan/Library/Developer/Xcode/DerivedData/QorosSales-fdvmkfwiibblhkeaqjznadykdyuj/Build/Products/Debug-iphonesimulator/Charts/Charts.framework

 
 

但是Xcode去ld的时候,看来是:
在查找库的路径时:
优先在:
/Users/crifan/Library/Developer/Xcode/DerivedData/QorosSales-fdvmkfwiibblhkeaqjznadykdyuj/Build/Products/Debug-iphonesimulator/
就找到了需要的,Charts的库:(i386的)Charts.framework
所以就没有,也不会,继续去到真正的我们所需要的:
(x86_64的)Charts下的Charts.framework

 
 

解决办法:
删除旧的残留的:
/Users/crifan/Library/Developer/Xcode/DerivedData/QorosSales-fdvmkfwiibblhkeaqjznadykdyuj/Build/Products/Debug-iphonesimulator/Charts.framework
-》
之后,不论是:
(1)使用Carthage去不用Charts库的在github作者提供的预先编译好的i386的Charts.framework:
carthage update –no-use-binaries Charts
(2)还是使用Cocoapods管理Charts
都可以从源码编译
都可以得到我们所需要的x86_64的Charts.framework
从而解决了ld出Charts.framework但是平台不对的问题。

 
 



但是:
最终,其实还是有点点诡异:
为何iPhone 5的时候,是可以正常编译运行的呢?
为何iPhone5的时候,没有加载错误的:
/Users/crifan/Library/Developer/Xcode/DerivedData/QorosSales-fdvmkfwiibblhkeaqjznadykdyuj/Build/Products/Debug-iphonesimulator/Charts/Charts.framework
的呢???

转载请注明:在路上 » [基本解决]使用iOS模拟器iPhone 6结果编译出错:file was built for i386 which is not the architecture being linked x86_64

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (1)

  1. 膜拜
    118年前 (2016-12-19)回复
85 queries in 0.227 seconds, using 22.15MB memory