使用静态Swift核心库编译Swift脚本 [英] Compile Swift script with static Swift core library

查看:132
本文介绍了使用静态Swift核心库编译Swift脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to execute a compiled Swift script on a computer which doesn't have Swift installed. But it seems by default the Swift Compiler uses dynamically linked libraries. Is it possible to include these libraries statically?

使用Docker复制的步骤:

Steps to reproduce using 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 build,将其传递给-Xswiftc:

swift build -Xswiftc -static-stdlib

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

If you get an ICU dependency error, install it:

apt-get install libicu-dev

这篇关于使用静态Swift核心库编译Swift脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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