微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

linux – 使用静态Swift核心库编译Swift脚本

我想在没有安装Swift的计算机上执行编译的Swift脚本.但认情况下,Swift编译器似乎使用动态链接库.
是否可以静态包含这些库?

使用Docker重现的步骤:

user@host:~# docker run -it swiftdocker/swift
root@16974ad4edb1:/# swift --version
Swift version 3.0-dev (LLVM dffa09ffd8, Clang 9f0d189820, Swift 1c720b8f84)
Target: x86_64-unkNown-linux-gnu
root@16974ad4edb1:/# echo 'print("Hello, world")' > helloworld.swift
root@16974ad4edb1:/# swiftc helloworld.swift
root@16974ad4edb1:/# ./helloworld
Hello, world
root@16974ad4edb1:/# exit
exit
user@host:~# docker cp 16974ad4edb1:/helloworld .
user@host:~# file helloworld
helloworld: ELF 64-bit LSB  executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=c4d42f6185b3d53ecf2dfb0c386263c17cb34675, not stripped
user@host:~# ./helloworld
./helloworld: error while loading shared libraries: libswiftCore.so: cannot open shared object file: No such file or directory

解决方法:

必须使用参数-static-stdlib:

swiftc -static-stdlib helloworld.swift

对于swift构建,将其传递给-Xswiftc:

swift build -Xswiftc -static-stdlib

如果您收到ICU依赖项错误,请安装它:

apt-get install libicu-dev

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐