cross compiling os x -> linux

Joakim via digitalmars-d-ldc digitalmars-d-ldc at puremagic.com
Wed Mar 30 02:57:54 PDT 2016


On Tuesday, 29 March 2016 at 10:59:41 UTC, yawniek wrote:
> is it possible to cross compile linux binaries from os x?

Yes and no, ldc is a very good cross-compiler and will work for 
that purpose most of the time: unfortunately it cannot link those 
binaries yet. ;)

> or in other words, is there a tutorial on how to build such a 
> toolchain?

No, especially because it will vary widely depending on your 
target.

> what i tried:
> ldc2 -of test -mtriple=i686-unknown-linux-gnu 
> -relocation-model=pic test.d
> ld: library not found for -lrt
> clang: error: linker command failed with exit code 1 (use -v to 
> see invocation)
> Error: /usr/bin/gcc failed with status: 1
>
> so i guess i need a directory with all my linux libraries and 
> the correct parameters?!

It may be that all you need is the right linux libraries to link 
against, ie that your linker could support the usual linux 
executable format of ELF-x86/x64 out of the box.  You can often 
get those libraries by downloading and unpacking the packages 
through which they're normally installed into your linux distro.

For an example of a cross-compiler toolchain that works well, you 
can look at the Android NDK, which has a download for the Mac too:

http://developer.android.com/ndk/downloads/index.html

By cloning the samples and running their build script in verbose 
mode (/path/to/ndk/ndk-build V=1), you can see exactly how they 
setup and use their toolchain and create something similar for 
yourself.


More information about the digitalmars-d-ldc mailing list