【问题标题】:How to install Swift package via package manager?如何通过包管理器安装 Swift 包?
【发布时间】:2015-12-19 09:47:45
【问题描述】:

我目前正在关注来自swift.org 的文档,以使用新的 Swift 包管理器。

我从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'

有什么想法吗?

【问题讨论】:

    标签: swift swift2 swift-package-manager


    【解决方案1】:

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

    【讨论】:

    【解决方案2】:

    您没有将新安装的 swift 添加到您的PATH。这样做的说明是here

    在 OS X 上:

    export PATH=/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin:"${PATH}"
    

    在 Linux 上:

    export PATH=/path/to/Swift/usr/bin:"${PATH}"
    

    然后测试它是否有效:

    swift build --version
    

    【讨论】:

    • 我也遇到了同样的问题。 error: unable to invoke subcommand: /Library/Developer/Toolchains/swift-2.2-SNAPSHOT-2016-01-25-a.xctoolchain/usr/bin/swift-build (No such file or directory)
    • 您需要下载开发快照而不是发布快照。
    • 谢谢~虽然看起来我花了几个小时,但我最终还是想通了。
    【解决方案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 日)快照,就可以了。

    【讨论】:

      【解决方案4】:

      我遇到了同样的问题,就我而言,我最近将我的 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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-10-08
        • 2013-12-09
        • 2018-06-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-05
        • 1970-01-01
        相关资源
        最近更新 更多