如何在macOS上为Linux构建Swift可执行文件 [英] How to build a swift executable for Linux on macOS
问题描述
我正在尝试在MacBook上为Linux vServer构建一个快速的可执行文件.
I am trying to build a swift executable on my MacBook for my Linux vServer.
我已经尝试使用 swiftc -target"x86_64-linux test.swift
,但是我的macOS swift编译器显示此错误:< unknown>:0:错误:无法加载标准目标'x86_64--linux'的库
I already tried using swiftc -target "x86_64-linux test.swift
, but my macOS swift compiler shows this error: <unknown>:0: error: unable to load standard library for target 'x86_64--linux'
所以我环顾四周,发现了这个问题:在OS X上进行Swift编译Linux吗?,并试用了示例脚本设置跨平台工具链.
So I looked around and found this question: Swift on OS X compiling for Linux? and tried out this example script from apple to setup a cross-platform toolchain.
尝试构建如脚本示例文本中所示的模块后,它进行了编译,但是在我的linux机器上,我现在收到此错误:加载共享库时出错:libswiftCore.so:无法打开共享库文件:没有这样的文件或目录
,这很奇怪,因为swift已正确安装在我的Linux机器上并且可以正常工作.
After trying to build a module like shown in the example text of the script, it compiled, but on my linux machine I now get this error: error while loading shared libraries: libswiftCore.so: cannot open shared object file: No such file or directory
which is strange, because swift is properly installed on my Linux machine and works.
那么在交叉编译项目时我做错了什么吗,或者我的Linux机器上有问题吗?我也想知道,是否有更简单的方法可以在macOS上为Linux编译项目,例如更改Xcode中的Build Settings或其他内容?
So have I done anything wrong while cross-compiling the project, or is there a problem on my Linux machine? Also I wonder, if there is a more simple way of compiling a project for Linux on macOS, like changing the Build Settings in Xcode or something?
在此先感谢,
乔纳斯(Jonas)
Thanks in advance,
Jonas
推荐答案
这仅表示无法找到链接的库.如果您的 libswiftCore.so
位于/usr/lib/swift/linux
,则可以运行 LD_LIBRARY_PATH =/usr/lib/swift/linux ./<可执行文件,适用于linux>
,并且会像魅力一样工作.
This just means it couldn't locate the linked library. If your libswiftCore.so
located at /usr/lib/swift/linux
you can run LD_LIBRARY_PATH=/usr/lib/swift/linux ./<your executable for linux>
and it will work like a charm.
您还可以设置 LD_LIBRARY_PATH
变量以仅执行二进制文件.
You can also set LD_LIBRARY_PATH
variable to just execute the binary.
这篇关于如何在macOS上为Linux构建Swift可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!