How to build a swift executable for Linux on macOS

混江龙づ霸主 提交于 2021-02-18 22:28:08

问题


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

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'

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.

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.

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?

Thanks in advance,
Jonas


回答1:


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.

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



来源:https://stackoverflow.com/questions/48242496/how-to-build-a-swift-executable-for-linux-on-macos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!