如何在macOS上为Linux构建swift可执行文件

时间:2021-02-14 07:33:22

I am trying to build a swift executable on my MacBook for my Linux vServer.

我正在尝试在我的MacBook上为我的Linux vServer构建一个swift可执行文件。

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'

我已经尝试过使用swiftc -target“x86_64-linux test.swift,但是我的macOS swift编译器显示了这个错误: :0:错误:无法为目标'x86_64加载标准库 - 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.

所以我环顾四周,发现了这个问题:Swift on OS X编译Linux?并从apple尝试了这个示例脚本来设置跨平台工具链。

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机器上我现在得到这个错误:加载共享库时出错:libswiftCore.so:无法打开共享对象文件:没有这样的文件或者目录很奇怪,因为swift已正确安装在我的Linux机器上并正常工作。

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?

那么在交叉编译项目时我做错了什么,或者我的Linux机器上有问题吗?另外我想知道,如果有更简单的方法在macOS上编译Linux项目,比如在Xcode中更改Build Settings还是什么?

Thanks in advance,
Jonas

在此先感谢,乔纳斯

1 个解决方案

#1


3  

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.

这只是意味着找不到链接的库。如果您的libswiftCore.so位于/ usr / lib / swift / linux,您可以运行LD_LIBRARY_PATH = / usr / lib / swift / linux ./ <您的linux可执行文件> 它将像魅力一样工作。

You can also set LD_LIBRARY_PATH variable to just execute the binary.

您还可以将LD_LIBRARY_PATH变量设置为仅执行二进制。

#1


3  

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.

这只是意味着找不到链接的库。如果您的libswiftCore.so位于/ usr / lib / swift / linux,您可以运行LD_LIBRARY_PATH = / usr / lib / swift / linux ./ <您的linux可执行文件> 它将像魅力一样工作。

You can also set LD_LIBRARY_PATH variable to just execute the binary.

您还可以将LD_LIBRARY_PATH变量设置为仅执行二进制。