Swift compile error: "cannot load underlying module for 'CoreGraphics'" with `import Foundation`
Swift compile error: "cannot load underlying module for 'CoreGraphics'" with `import Foundation`
使用 Swift DEVELOPMENT-SNAPSHOT-2016-02-08-a
,我正在尝试使用 swift build
构建项目,但是一旦我添加行 import Foundation
,我就会收到错误消息:
[I] ~/Dropbox/Projects/test
↪ swift build --clean; and swift build
Compiling Swift Module 'test' (1 sources)
<unknown>:0: error: cannot load underlying module for 'CoreGraphics'
<unknown>:0: note: did you forget to set an SDK using -sdk or SDKROOT?
<unknown>:0: note: use "xcrun -sdk macosx swiftc" to select the default OS X SDK installed with Xcode
<unknown>:0: error: build had 1 command failures
error: exit(1): ["/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-02-08-a.xctoolchain/usr/bin/swift-build-tool", "-f", "/Users/me/Dropbox/Projects/test/.build/debug/test.o/llbuild.yaml"]
运行 xcrun -sdk macosx
导致 "no such SDK: 'machos'" 错误:
↪ xcrun -sdk macosx swift build 0@10:34:03
<unknown>:0: warning: no such SDK: 'macosx'
<unknown>:0: warning: no such sysroot directory: 'macosx'
<unknown>:0: error: cannot load underlying module for 'Darwin'
error: exit(1): ["/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-02-08-a.xctoolchain/usr/bin/swiftc", "--driver-mode=swift", "-I", "/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-02-08-a.xctoolchain/usr/lib/swift/pm", "-L", "/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-02-08-a.xctoolchain/usr/lib/swift/pm", "-lPackageDescription", "-target", "x86_64-apple-macosx10.10", "/Users/me/Dropbox/Projects/test/Package.swift"]
这只有main.swift,内容是:
import Foundation
print("Hello, world!")
Packages.swift 中没有定义任何依赖项。
真不知道这是怎么回事。这在我的 Ubuntu 14.04 DigitalOcean VPS 以及 Xcode 7.3 Beta 5.
中编译得很好
OS X 10.11.3
↪ swift --version 0@10:21:16
Apple Swift version 3.0-dev (LLVM a7663bb722, Clang 4ca3c7fa28, Swift 1c2f40e246)
Target: x86_64-apple-macosx10.9
您的 [/Applications] 目录中是否有 Xcode.app 的稳定版本?如果您只有 Xcode-beta.app,这很可能是导致此错误的原因。尝试创建 Xcode-beta.app 到 Xcode.app:
的符号链接
$ ln -s /Applications/Xcode-beta.app /Applications/Xcode.app
(向 anton for the answer 致敬)。
使用 Swift DEVELOPMENT-SNAPSHOT-2016-02-08-a
,我正在尝试使用 swift build
构建项目,但是一旦我添加行 import Foundation
,我就会收到错误消息:
[I] ~/Dropbox/Projects/test
↪ swift build --clean; and swift build
Compiling Swift Module 'test' (1 sources)
<unknown>:0: error: cannot load underlying module for 'CoreGraphics'
<unknown>:0: note: did you forget to set an SDK using -sdk or SDKROOT?
<unknown>:0: note: use "xcrun -sdk macosx swiftc" to select the default OS X SDK installed with Xcode
<unknown>:0: error: build had 1 command failures
error: exit(1): ["/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-02-08-a.xctoolchain/usr/bin/swift-build-tool", "-f", "/Users/me/Dropbox/Projects/test/.build/debug/test.o/llbuild.yaml"]
运行 xcrun -sdk macosx
导致 "no such SDK: 'machos'" 错误:
↪ xcrun -sdk macosx swift build 0@10:34:03
<unknown>:0: warning: no such SDK: 'macosx'
<unknown>:0: warning: no such sysroot directory: 'macosx'
<unknown>:0: error: cannot load underlying module for 'Darwin'
error: exit(1): ["/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-02-08-a.xctoolchain/usr/bin/swiftc", "--driver-mode=swift", "-I", "/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-02-08-a.xctoolchain/usr/lib/swift/pm", "-L", "/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-02-08-a.xctoolchain/usr/lib/swift/pm", "-lPackageDescription", "-target", "x86_64-apple-macosx10.10", "/Users/me/Dropbox/Projects/test/Package.swift"]
这只有main.swift,内容是:
import Foundation
print("Hello, world!")
Packages.swift 中没有定义任何依赖项。
真不知道这是怎么回事。这在我的 Ubuntu 14.04 DigitalOcean VPS 以及 Xcode 7.3 Beta 5.
中编译得很好OS X 10.11.3
↪ swift --version 0@10:21:16
Apple Swift version 3.0-dev (LLVM a7663bb722, Clang 4ca3c7fa28, Swift 1c2f40e246)
Target: x86_64-apple-macosx10.9
您的 [/Applications] 目录中是否有 Xcode.app 的稳定版本?如果您只有 Xcode-beta.app,这很可能是导致此错误的原因。尝试创建 Xcode-beta.app 到 Xcode.app:
的符号链接$ ln -s /Applications/Xcode-beta.app /Applications/Xcode.app
(向 anton for the answer 致敬)。