How to install Swift package via package manager?

╄→尐↘猪︶ㄣ 提交于 2019-12-21 03:38:21

问题


I am currently following the document from swift.org to play around with the new Swift Package Manager.

I cloned the demo project from Github and run the following command from terminal.

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

While I run swift build, error arise.

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

Any idea?


回答1:


I stuck for an hour. Sadly, it's just an epic fail that downloading the wrong swift package. If you want to use swift build, MAKE SURE you download the development version.




回答2:


You did not add the newly installed swift to your PATH. The instructions for doing that are here.

On OS X:

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

On Linux:

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

Then to test it works:

swift build --version



回答3:


I think it is a problem with the latest snapshot:

  • Ubuntu 14.04 Swift 2.2 Snapshot of January 11 contains swift-build in usr/bin
  • Ubuntu 14.04 Swift 2.2 Snapshot of January 25 doesn't contain swift-build in usr/bin

Besides, the January 25 release also seems to miss other files (libFoundation.so and libXCTest.so in usr/lib/swift/linux for instances).

Either there has been a structure change....or, simply, the latest snapshot had a problem ;) While they fix the snapshot, simply take the older (January 11th) snapshot, and you should be fine.




回答4:


I was facing the same issue and in my case, I recently updated my Xcode to 8.2.1 and swift 3.0 comes with it. I was getting this log.

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

The path it was taking was incorrect. It was suppose to be:

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


To change the path, run this command.

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

And DONE.
Run : swift build again on your project and if you get this error.

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

then you need to change the SDK path as well.
In my case, I had two .sdk at path

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

MacOSX.sdk  MacOSX10.12.sdk

To know what is your SDK path, run this command.

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

My case i got this.

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

To change it run this command.

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

and NOW DONE. Try running swift build now.



来源:https://stackoverflow.com/questions/34369366/how-to-install-swift-package-via-package-manager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!