44

I recently reformatted my Mac. Today I tried building a swift executable via Terminal to start a server-side swift project. Here are the commands I've used:

  1. swift package init --type executable

  2. swift build

Upon running swift build, I got the following errors:

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'

I'm running Xcode 8.3.1.

Thanks in advance!

2 Answers 2

116

Try fixing the SDK path (yours appears incorrect):

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

You might have this result:

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

Switch the default SDK location by invoking:

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

If that doesn't work then take a look inside the (normal) SDK path:

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

You should see the SDK's within that directory; if not you'll need to download them.

Sign up to request clarification or add additional context in comments.

6 Comments

for the search engines: this fixed my issue with a kotlin mpp build that was getting stuck with xcrun: error: SDK "iphoneos" cannot be located
I strongly suspect this (which happens on all my macs) is due to homebrew installation, which I just noticed is installing the command-line tools even if Xcode is already installed.
@DaveAbrahams It can happen for various reasons, although that doesn't sound good. I personally use MacPorts, which I find much less invasive than homebrew.
@DaveAbrahams I can confirm that. I just went through a similar issue and my environment was setup exactly the same. I had just installed homebrew and I noticed it was installing CLI tools.
Thank you for the answer, it worked for me. And I agree with @DaveAbrahams. The same thing just happened to me because of HOMEBREW INSTALLATION. After installing it I started to run into many problems when running tasks like swift build. It seems that Homebrew installs CommandLineTools in this path /Library/Developer/CommandLineTools (which includes the macOSX.sdk) when we are supposed to have all those stuff in the default /Applications/Xcode.app/Contents/Developer.
|
4

Select a version of Xcode which can run the swift build command by running, for instance:

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

Where Xcode-8.3.3 is the name of your Xcode application

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.