iComputerfreak
iComputerfreak

Reputation: 1011

How to build a swift executable for Linux on macOS

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

Upvotes: 8

Views: 2696

Answers (1)

Devan
Devan

Reputation: 78

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.

Upvotes: 5

Related Questions