Best Way to Build Cross Toolchains on MAC Os X

How to cross compile from Mac OS X to Linux x86?

Your simplest solution is to just run CentOS 5.3 in a VM (e.g. Sun VirtualBox). This requires minimal setup, has quite reasonable overhead (assuming an Intel Mac), and you'll be able to actually test and debug what you are building.

If you really insist on cross-compiling, you must build a cross-compiler. Instructions are here and here, but beware: it will likely take you several days to get it right, and then you'll still need a VM to test the result, so I don't see any point in doing it that way.

How to Compile for OS X in Linux or Windows?

There appears to be some scripts that have been written to help get you set up cross compiling for the Mac; I can't say how good they are, or how applicable to your project. In the documentation, they refer to these instructions for cross-compiling for 10.4, and these ones for cross compiling for 10.5; those instructions may be more helpful than the script, depending on how well the script fits your needs.

If your program is free or open source software, then you may wish instead to create a MacPorts portfile (documentation here), and allow your users to build your program using MacPorts; that is generally the preferred way to install portable free or open source software on Mac OS X. MacPorts has been known to run on Linux in the past, so it may be possible to develop and test your Portfile on Linux (though it will obviously need to be tested on a Mac).

Cross-compiler for Linux on Mac OS X?

In order to build binaries for architectures different that your build host, you need far more than just a cross-compiler - you need a full-blown toolchain, which can be a real pain to create, as you probably discovered.

A couple of approaches:

  • Use a proper Linux distribution in a virtual machine, such as VirtualBox. If you only want to build binaries for Linux/i386 on an MacOSX/x86_64 host, this is - in my opinion - the easiest, safest and most clean solution. It is not a cross-compiler, of course, but it works and it has the added advantage that you can actually test your executables.

  • Use a script such crosstool-NG (a descendant of the original crosstool) to automatically build the toolchain - definitely easier than building it on your own, although you may have to compromise for slightly older compiler versions.

Cross compile Go on OSX?

With Go 1.5 they seem to have improved the cross compilation process, meaning it is built in now. No ./make.bash-ing or brew-ing required. The process is described here but for the TLDR-ers (like me) out there: you just set the GOOS and the GOARCH environment variables and run the go build.

For the even lazier copy-pasters (like me) out there, do something like this if you're on a *nix system:

env GOOS=linux GOARCH=arm go build -v github.com/path/to/your/app

You even learned the env trick, which let you set environment variables for that command only, completely free of charge.

How to build a swift executable for Linux on macOS

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.

Cross-compile Swift code for Raspberry Pi on macOS

To answer my own question, the current best solution (very recent) is:
https://github.com/CSCIX65G/swift-mac2arm-x-compile-toolchain

That provides the needed toolchains, etc. for building on macOS for the R Pi.
Best instructions for remote debugging (using lldb) can be found here:
https://lldb.llvm.org/use/remote.html

Note that on macOS you need to use the version of lldb provided by the toolchain, e.g.:

[path_to_toolchains]/Toolchains/arm64-swift.xctoolchain/usr/bin/lldb -o "platform select remote-linux" -o "platform connect connect://ipaddress:port" -o "file ./remoteProgram"

Still looking to connect the lldb debugger to Xcode run on the Mac. If that can be done, the development cycle is complete.



Related Topics



Leave a reply



Submit