无法编译“hello world"在 Ubuntu 14.04 上使用 Swift 编程 [英] Unable to compile "hello world" program with Swift on Ubuntu 14.04

查看:39
本文介绍了无法编译“hello world"在 Ubuntu 14.04 上使用 Swift 编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Ubuntu 14.04

发行商 ID:Ubuntu描述:Ubuntu 14.04.3 LTS发布: 14.04代号:可信赖

并尝试编译一个 hello world Swift 程序.

print("Hello World!")

我已验证下载:

 gpg --verify swift-2.2-SNAPSHOT-2015-12-10-a-ubuntu14.04.tar.gz.siggpg:使用 RSA 密钥 ID 412B37AD 于太平洋标准时间 2015 年 12 月 10 日星期四下午 07:17:37 进行签名gpg:来自Swift Automatic Signing Key #1 <swift-infrastructure@swift.org>"的良好签名gpg:警告:此密钥未经过可信签名认证!gpg:没有迹象表明签名属于所有者.主键指纹:7463 A81A 4B2E EA1B 551F FBCF D441 C977 412B 37AD

但是当我尝试编译 hello world 程序时出现此错误:

<代码>>swiftc hello_world.swift<unknown>:0: 错误:打开模块SwiftShims"的导入文件:没有这样的文件或目录

如果我启动 Swift REPL,我会收到类似的错误:

~$ swift欢迎使用 Swift 2.2-dev(LLVM 7bae82deaa、Clang 53d04af5ce、Swift 5995ef2acd).输入 :help 寻求帮助.1>y = 6打开模块SwiftShims"的导入文件:没有这样的文件或目录1>

如果我按照此处给出的说明 在使用swift build"和swiftc"来编译 Hello World Swift 程序时,我得到了一个不同的错误:

$ 快速构建<unknown>:0: 错误:打开模块Swift"的导入文件:没有这样的文件或目录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/滑板车/代码/swift/helloworld-project/Package.swift"]

执行解释器:

$ swift hello_world.swift

给予

:0: 错误:打开模块SwiftShims"的导入文件:没有这样的文件或目录

strace 尝试快速运行时出错:

$ strace -o/tmp/swift.log -- swift <(echo '1 + 1')<unknown>:0: 错误:打开模块SwiftShims"的导入文件:没有这样的文件或目录

<块引用>

open("/home/user/Programs/Swift/V2.2/lib/swift/linux/x86_64/SwiftShims.swiftmodule",O_RDONLY) = -1 ENOENT(没有那个文件或目录)

解决方案

很抱歉将本应真正作为评论内容的内容添加为答案,但评论太长了.

据我所知,这确实与 Linux 上的 Swift:第一步工作.我一直在业余时间自己研究这个问题,但到目前为止没有运气.提出另一个问题的用户一直在追求它,并且最近有一些有趣的更新.

一些尝试:

看看 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(开发文件)ii libstdc++6:amd64 4.8.4-2ubuntu1~14.04 amd64 GNU 标准 C++ 库 v3user@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 应该可以正常工作而不会出现问题.

Using Ubuntu 14.04

Distributor ID: Ubuntu
Description:    Ubuntu 14.04.3 LTS
Release:    14.04
Codename:   trusty

and trying to compile a hello world Swift program.

print("Hello World!")

I have verified the download:

 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

But when I try and compile the hello world program I get this error:

> swiftc hello_world.swift 
<unknown>:0: error: opening import file for module 'SwiftShims': No such file or directory

If I start up the Swift REPL I get a similar error:

~$ 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>  

If I follow the instructions given here on using "swift build" versus "swiftc" for compiling a Hello World Swift program, I get a different error:

$ 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"]

Executing the interpreter:

$ swift hello_world.swift

gives

<unknown>:0: error: opening import file for module 'SwiftShims': No such file or directory

strace gets an error trying to run 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)

解决方案

Sorry for adding as an answer what should have really been a comment content-wise, but it is a little too long for a comment.

As far as I can tell, this is indeed the same problem as described in Swift on Linux: Make very first step work. I have been looking into this myself in my spare time, but no luck so far. The user who asked the other question has been pursuing it and has some interesting recent updates there.

A few things to try:

See if the swift interpreter works. Just type swift hello_world.swift and see what happens. I don't think it will work. If it does not, then run the strace command as follows:

strace -o /tmp/swift.log -- swift <(echo '1 + 1')

and look at /tmp/swift.log. See what files cannot be found, especially near the end of the output. Warning: even on a system where the error doesn't happen (I haven't been able to reproduce it yet), the strace output shows a lot of No such file... errors.

You can also try swift and swiftrc with the -v option to enable verbose output and see if you notice anything suspicious.

Update 1/2/2016:

The question referenced earlier has been updated with a possible solution to the problem: get rid of non-standard installations of gcc, g++, libgcc, and libstdc++. Please see the comments in the other question.

Update 1/3/2016:

Using the clues from the discussion on the other question, I've been able to reproduce the problem by installing gcc-5.1.0 from source and pre-pending the location of the newly-installed libstdc++.so.6 to the LD_LIBRARY_PATH variable.

The problem could be solved as follows: 1) Figure out where libstdc++.so.6 from the older package is installed. On my system:

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) Prepend the location of libstdc++.so.6 to $LD_LIBRARY_PATH:

export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH

3) Double-check that the swift binary is using the correct shared library:

user@ubuntu14:~$ ldd `which swift` | grep libstdc++
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fdd1476b000)

Now Swift should work without the error in question.

这篇关于无法编译“hello world"在 Ubuntu 14.04 上使用 Swift 编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆