8

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

iComputerfreak
  • 890
  • 2
  • 8
  • 22

1 Answers1

5

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.

Devan
  • 78
  • 2
  • 10
  • Sure there is no typo in the command you wrote? `LD_LIBRARY_PATH/usr/lib/swift/linux` is not a valid command on my machine. `-bash: LD_LIBRARY_PATH/usr/lib/swift/linux: No such file or directory` – iComputerfreak Jul 06 '18 at 11:49
  • Never mind. Got it. There is a `=` missing between your `LD_LIBRARY_PATH` and the folder. Thanks a lot! It worked :) – iComputerfreak Jul 06 '18 at 11:51