使用 Ubuntu 14.04
Distributor ID: Ubuntu
Description: Ubuntu 14.04.3 LTS
Release: 14.04
Codename: trusty
并尝试编译一个 hello world Swift 程序。
print("Hello World!")
我已经验证了下载:
gpg --verify swift-2.2-SNAPSHOT-2015-12-10-a-ubuntu14.04.tar.gz.sig
gpg: Signature made Thu 10 Dec 2015 07:17:37 PM PST using RSA key ID 412B37AD
gpg: Good signature from "Swift Automatic Signing Key #1 <swift-infrastructure@swift.org>"
gpg: WARNING: This key is not certified with a trusted signature!
gpg: There is no indication that the signature belongs to the owner.
Primary key fingerprint: 7463 A81A 4B2E EA1B 551F FBCF D441 C977 412B 37AD
但是当我尝试编译 hello world 程序时,我得到了这个错误:
> swiftc hello_world.swift
<unknown>:0: error: opening import file for module 'SwiftShims': No such file or directory
如果我启动 Swift REPL,我会遇到类似的错误:
~$ swift
Welcome to Swift version 2.2-dev (LLVM 7bae82deaa, Clang 53d04af5ce, Swift 5995ef2acd). Type :help for assistance.
1> y = 6
opening import file for module 'SwiftShims': No such file or directory
1>
如果我按照说明进行操作 given here关于使用“swift build”和“swiftc”来编译 Hello World Swift 程序,我得到了一个不同的错误:
$ swift build
<unknown>:0: error: opening import file for module 'Swift': No such file or directory
swift-build: exit(1): ["/home/scooter/Programs/Swift/V2.2/bin/swiftc", "--driver-mode=swift", "-I", "/home/scooter/Programs/Swift/V2.2/lib/swift/pm", "-L", "/home/scooter/Programs/Swift/V2.2/lib/swift/pm", "-lPackageDescription", "/home/scooter/code/swift/helloworld-project/Package.swift"]
执行解释器:
$ swift hello_world.swift
给予
<unknown>:0: error: opening import file for module 'SwiftShims': No such file or directory
strace 在尝试运行 swift 时遇到错误:
$ strace -o /tmp/swift.log -- swift <(echo '1 + 1')
<unknown>:0: error: opening import file for module 'SwiftShims': No such file or directory
open("/home/user/Programs/Swift/V2.2/lib/swift/linux/x86_64/SwiftShims.swiftmodule", O_RDONLY) = -1 ENOENT (No such file or directory)
最佳答案
很抱歉添加了一个真正应该是评论内容的答案,但对于评论来说有点太长了。
据我所知,这确实与 Swift on Linux: Make very first step work 中描述的问题相同.我一直在业余时间自己研究这个问题,但到目前为止还没有运气。提出其他问题的用户一直在追求它,并且最近有一些有趣的更新。
一些尝试:
查看 swift 解释器是否工作。只需输入 swift hello_world.swift
看看会发生什么。我不认为它会工作。如果没有,则运行 strace
命令如下:
strace -o /tmp/swift.log -- swift <(echo '1 + 1')
并查看/tmp/swift.log
.查看找不到哪些文件,尤其是在输出末尾附近。警告:即使在没有发生错误的系统上(我还无法重现它),strace
输出显示很多 No such file...
错误。
您还可以尝试使用带有 -v 选项的 swift 和 swiftrc 来启用详细输出,看看您是否注意到任何可疑的东西。
2016 年 1 月 2 日更新:
前面提到的问题已更新为问题的可能解决方案:摆脱 gcc、g++、libgcc 和 libstdc++ 的非标准安装。请参阅其他问题中的评论。
2016 年 1 月 3 日更新:
使用其他问题讨论中的线索,我已经能够通过从源代码安装 gcc-5.1.0 并将新安装的 libstdc++.so.6 的位置预先挂起到LD_LIBRARY_PATH 变量。
问题可以通过以下方式解决:
1)找出libstdc++.so.6
在哪里从旧包安装。在我的系统上:
user@ubuntu14:~$ dpkg -l | grep libstdc++
ii libstdc++-4.8-dev:amd64 4.8.4-2ubuntu1~14.04 amd64 GNU Standard C++ Library v3 (development files)
ii libstdc++6:amd64 4.8.4-2ubuntu1~14.04 amd64 GNU Standard C++ Library v3
user@ubuntu14:~$ dpkg -L libstdc++6 | grep libstdc++.so
/usr/share/gdb/auto-load/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19-gdb.py
/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19
/usr/lib/x86_64-linux-gnu/libstdc++.so.6
2) 前置 libstdc++.so.6
的位置至 $LD_LIBRARY_PATH
:
export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH
3) 仔细检查 swift 二进制文件是否使用了正确的共享库:
user@ubuntu14:~$ ldd `which swift` | grep libstdc++
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fdd1476b000)
现在 Swift 应该可以正常工作了,不会出现问题。
关于swift - 无法在 Ubuntu 14.04 上使用 Swift 编译 "hello world"程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34237615/