最新消息:20210917 已从crifan.com换到crifan.org

【已解决】Xcode8的swift 3中链接库失败:error The following binaries use incompatible versions of Swift

Swift crifan 1369浏览 0评论

在Cartfile中设置:

github “robb/Cartography”
github “DaveWoodCom/XCGLogger” “swift_3.0”
github “Alamofire/Alamofire” ~> 3.4
github “SwiftyJSON/SwiftyJSON”
github “rhodgkins/SwiftHTTPStatusCodes” ~> 3.0
github “thii/SwiftHEXColors” “swift-3.0”

后,去用carthage update去更新库文件

➜  FreeShadowsocks carthage update –platform iOS
*** Fetching SwiftHEXColors
*** Fetching SwiftHTTPStatusCodes
*** Fetching XCGLogger
*** Fetching SwiftyJSON
*** Fetching Alamofire
*** Fetching Cartography
*** Checking out Alamofire at “3.5.1”
*** Checking out SwiftHTTPStatusCodes at “3.1.0”
*** Checking out SwiftHEXColors at “f4b98e298528fd9d88b10ab55e806d29ce497daa”
*** Checking out XCGLogger at “2fd27c92eb102bcf09f3176a230e42e38cacd4a2”
*** Downloading SwiftyJSON.framework binary at “3.1.1”
*** Checking out Cartography at “1.0.1”
*** xcodebuild output can be found in /var/folders/46/2hjxz38n22n3ypp_5f6_p__00000gn/T/carthage-xcodebuild.jkF4ZT.log
*** Building scheme “Alamofire iOS” in Alamofire.xcworkspace
*** Building scheme “Cartography-iOS” in Cartography.xcworkspace
*** Building scheme “SwiftHEXColors” in SwiftHEXColors.xcodeproj
*** Building scheme “HTTPStatusCodes” in HTTPStatusCodes.xcodeproj
*** Building scheme “XCGLogger (iOS)” in XCGLogger.xcodeproj

然后再去Xcode中编译项目,结果出错:

(null):  The following binaries use incompatible versions of Swift:
error: The following binaries use incompatible versions of Swift:
/Users/crifan/Library/Developer/Xcode/DerivedData/FreeShadowsocks-bwfhhwqhqeqaxegdlzclfjrqsews/Build/Products/Debug-iphonesimulator/FreeShadowsocks.app/FreeShadowsocks
/Users/crifan/dev/dev_root/crifan/FeeeShadowsocks/FreeShadowsocks/Carthage/Build/iOS/Alamofire.framework/Alamofire

然后改为:

github “robb/Cartography”
github “DaveWoodCom/XCGLogger” “swift_3.0”
github “Alamofire/Alamofire” ~> 4.0
github “SwiftyJSON/SwiftyJSON”
github “rhodgkins/SwiftHTTPStatusCodes” ~> 3.0
github “thii/SwiftHEXColors” “swift-3.0”

重新update:

➜  FreeShadowsocks carthage update –platform iOS
*** Fetching SwiftHEXColors
*** Fetching SwiftHTTPStatusCodes
*** Fetching XCGLogger
*** Fetching SwiftyJSON
*** Fetching Alamofire
*** Fetching Cartography
*** Checking out Alamofire at “4.0.1”
*** Checking out SwiftHEXColors at “f4b98e298528fd9d88b10ab55e806d29ce497daa”
*** Checking out Cartography at “1.0.1”
*** Checking out XCGLogger at “2fd27c92eb102bcf09f3176a230e42e38cacd4a2”
*** Downloading SwiftyJSON.framework binary at “3.1.1”
*** Checking out SwiftHTTPStatusCodes at “3.1.0”
*** xcodebuild output can be found in /var/folders/46/2hjxz38n22n3ypp_5f6_p__00000gn/T/carthage-xcodebuild.8y7lxE.log
*** Building scheme “Alamofire iOS” in Alamofire.xcworkspace
*** Building scheme “Cartography-iOS” in Cartography.xcworkspace
*** Building scheme “SwiftHEXColors” in SwiftHEXColors.xcodeproj
*** Building scheme “HTTPStatusCodes” in HTTPStatusCodes.xcodeproj
*** Building scheme “XCGLogger (iOS)” in XCGLogger.xcodeproj

然后Xcode中clean后重新编译项目

就可以,继续运行项目了:

【总结】

在Xcode升级到8后,swift是3.0,就要求所有链接的库,也都是swift 3.0(的代码编译出来的),而不能是2.3或更早的

而之前设置Cartfile为:

github “Alamofire/Alamofire” ~> 3.4

表示和3.4兼容的,然后去:

carthage update

会检测到最新的是,和3.4兼容的版本是3.5.1:

*** Checking out Alamofire at “3.5.1”

然后对应代码,是2.3之类的,不是swift 3.0

所以Xcode编译出错:

The following binaries use incompatible versions of Swift

解决办法是:

指定Cartfile中为:

github “Alamofire/Alamofire” ~> 4.0

表示和4.0的兼容,对应着swift是3.0,

然后去carthage update得到最新的是:

*** Checking out Alamofire at “4.0.1”

然后编译出来的库,就是兼容swift 3.0的,

Xcode就可以正常链接了。

转载请注明:在路上 » 【已解决】Xcode8的swift 3中链接库失败:error The following binaries use incompatible versions of Swift

发表我的评论
取消评论

表情

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

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
99 queries in 0.189 seconds, using 23.36MB memory