首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用静态Swift核心库编译Swift脚本

用静态Swift核心库编译Swift脚本
EN

Stack Overflow用户
提问于 2016-05-24 09:54:36
回答 1查看 3.5K关注 0票数 14

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

使用Docker复制的步骤:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-24 10:52:37

必须使用参数-static-stdlib

代码语言:javascript
复制
swiftc -static-stdlib helloworld.swift

对于swift build,将其传递给-Xswiftc

代码语言:javascript
复制
swift build -Xswiftc -static-stdlib

如果收到ICU依赖关系错误,请安装它:

代码语言:javascript
复制
apt-get install libicu-dev
票数 16
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37410156

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档