Cross compile linux -> OS X

kinke noone at nowhere.com
Mon Nov 20 20:42:28 UTC 2017


On Monday, 20 November 2017 at 18:01:02 UTC, Oleg B wrote:
> Hello. It's possible to build application on linux for OS X? 
> And if yes what I need to do for this? Also interesting works 
> with libraries as gtk-d.

Hi Oleg,

of course it's possible, I just don't know how much of a hassle 
it is. The steps are always the same:

1) Compile objects/static libs via `-mtriple=x86_64-darwin` (or a 
more specific triple, I'm not an Apple user).
2) Get ahold of druntime/Phobos for OSX; the simplest solution is 
to copy the libs from the official LDC package for OSX; compiling 
them yourself via the ldc-build-runtime tool 
(https://wiki.dlang.org/Building_LDC_runtime_libraries) would be 
another option but requires a full C cross-toolchain.
3) Link with a linker capable of outputting OSX binaries; you'll 
also need the OSX C runtime libs/init objects as druntime is 
built on top of the C runtime. I guess Apple doesn't provide a 
cross-toolchain by themselves, so you may have to copy the 
libs/objects over from an Xcode installation and link manually 
via LLD.

Points 1 and 2 are trivial; point 3, cross-linking, is definitely 
the biggest hurdle. It's not specific to D though, so any 
guide/tutorial you find about how to cross-compile/link C(++) 
code from Linux to OSX will be applicable here as well.


More information about the digitalmars-d-ldc mailing list