Having trouble cross compiling with LDC

Jacob Carlborg doob at me.com
Sun Dec 9 08:50:09 UTC 2018


On Saturday, 8 December 2018 at 22:16:32 UTC, o wrote:
> I have heard that LDC has great support for cross compilation, 
> but I can't figure out how to use it.
>
> I have a linux x64 host, and I am looking for a definitive step 
> by step guide to setting up LDC to cross compile targeting 
> windows x64, macosx, and linux arm64(raspberry pi).
>
> From what I understand, the basic steps are as follows (but I 
> don't know how to actually go about doing them):
>
> 1. Use ldc-build-runtime to compile phobos library binaries for 
> the target OS/Arch.

If LDC already provides a release for this target, as it does 
with macOS and Windows, you can just download that and extract 
druntime and Phobos.

> 2. Run LDC, and tell it where to find the phobos binaries from 
> step 1, and tell it to use lld as a linker.

LLD will not work for targeting macOS, you need the LD64 linker, 
built for Linux. Not sure if it will work for Linux Arm64.

> 3. LDC outputs an executable that can run on the target 
> platform.
>
> But, how do I actually go about doing these steps? How do I use 
> ldc-build-runtime? How do I tell LDC to use the cross-compiled 
> phobos/runtime instead of the default one?

I've created a Docker image (or rather a Dockerfile) for 
cross-compiling to macOS [1] and one for cross-compiling to 
Windows [2]. These Docker images are configured to output 
binaries for the target by default. Note that the SDKs/libraries 
are downloaded from someone's Dropbox account.

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

--
/Jacob Carlborg


More information about the Digitalmars-d mailing list