Thread overview
Cross compile linux -> OS X
Nov 20, 2017
Oleg B
Nov 20, 2017
kinke
Nov 21, 2017
Jacob Carlborg
Nov 23, 2017
Oleg B
November 20, 2017
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.
November 20, 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.
November 21, 2017
On 2017-11-20 19:01, 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.

I have a Dockerfile for that [1]. Just invoke "ldc2" as usual, it's already configured to cross-compile.

[1] https://github.com/jacob-carlborg/docker-ldc-darwin/blob/master/Dockerfile

-- 
/Jacob Carlborg
November 23, 2017
On Tuesday, 21 November 2017 at 20:40:30 UTC, Jacob Carlborg wrote:
> On 2017-11-20 19:01, 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.
>
> I have a Dockerfile for that [1]. Just invoke "ldc2" as usual, it's already configured to cross-compile.
>
> [1] https://github.com/jacob-carlborg/docker-ldc-darwin/blob/master/Dockerfile

Thanks! I try it near future.