如何通过包管理器安装Swift包?

时间:2015-12-19 09:47:45

标签: swift swift2 swift-package-manager

我目前正在关注swift.org的文档,以使用新的Swift Package Manager。

我从Github克隆了演示项目,并从终端运行以下命令。

git clone https://github.com/apple/example-package-dealer.git
cd example-package-dealer
swift build
.build/debug/Dealer

当我运行swift build时,会出现错误。

<unknown>:0: error: no such file or directory: 'build'

有什么想法吗?

3 个答案:

答案 0 :(得分:18)

我停了一个小时。可悲的是,下载错误的swift包只是一个史诗般的失败。如果您想使用swift build,请务必下载开发版本。

答案 1 :(得分:3)

我认为这是最新快照的问题:

  • Ubuntu 14.04 Swift 2.2 1月11日快照包含usr / bin中的swift-build
  • Ubuntu 14.04 Swift 2.2 1月25日的快照不包含usr / bin中的swift-build

此外,1月25日版本似乎也错过了其他文件(例如usr / lib / swift / linux中的libFoundation.so和libXCTest.so)。

要么有结构改变......或者,简单地说,最新的快照有问题;) 虽然他们修复了快照,但只需拍摄旧的(1月11日)快照,你应该没问题。

答案 2 :(得分:3)

我遇到了同样的问题,在我的情况下,我最近将我的Xcode更新为8.2.1并且swift 3.0附带了它。 我得到了这个日志。

Ranvijay-Mac-mini:PerfectTemplate ranaranvijaysingh$ swift build
error: unable to invoke subcommand: /Library/Developer/CommandLineTools/usr/bin/swift-build (No such file or directory)

它采取的路径不正确。它被认为是:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin


要更改路径,请运行此命令。

export PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:$PATH

完成。
在项目中再次运行swift build,如果出现此错误。

xcrun: error: unable to lookup item 'PlatformPath' from command line tools installation
xcrun: error: unable to lookup item 'PlatformPath' in SDK '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk'
error: Invalid platform path

然后您还需要更改SDK路径 就我而言,我在路径上有两个.sdk

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/ 

MacOSX.sdk  MacOSX10.12.sdk

要知道您的SDK路径是什么,请运行此命令。

xcrun --sdk macosx --show-sdk-path

我的情况我得到了这个。

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk

要更改它,请运行此命令。

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

现在完成。 立即尝试运行swift build

相关问题