在终端中运行Swift构建导致“平台路径”错误

时间:2017-04-14 20:08:21

标签: swift xcode

我最近重新格式化了我的Mac。今天我尝试通过Terminal构建一个swift可执行文件来启动服务器端swift项目。以下是我使用过的命令:

  1. swift package init --type executable

  2. 快速构建

  3. 运行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'
    

    我正在运行 Xcode 8.3.1

    提前致谢!

2 个答案:

答案 0 :(得分:23)

尝试修复SDK路径(您的路径显示不正确):

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

您可能会得到以下结果:

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

通过调用:

切换默认的SDK位置
$ sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

如果这不起作用,请查看(普通)SDK路径:

$ ls -lat /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/

您应该在该目录中看到SDK;如果没有,你需要下载它们。

答案 1 :(得分:-1)

选择一个可以运行swift build命令的Xcode版本,例如:

sudo xcode-select -switch /Applications/Xcode-8.3.3.app