Linux -> Windows crosscompiler

kinke via digitalmars-d-ldc digitalmars-d-ldc at puremagic.com
Mon May 15 10:58:22 PDT 2017


On Monday, 15 May 2017 at 09:27:36 UTC, Marvin G├╝lker wrote:
> Hi everyone,
>
> I am mainly a Linux developer and find working on Windows 
> rather complicated. My most recent try confirmed that; I wanted 
> to write a D application using GraphicsMagick's C interface -- 
> now I have a mixture of compilers on my Windows machine (MinGW 
> GCC, Msys2 GCC, MSVC, LDC, DMD) and I still get linking errors.
>
> That only for the context. Since I previously had good 
> experience in
> using a Linux -> Windows crosscompiler for regular C/C++ 
> (MXE[1]) I thought
> it could be possible to have something similar for D. Until now 
> I have
> been using dmd, but Internet research told me dmd cannot be 
> built as a
> crosscompiler. GDC appears to be a one-man show and is still 
> pending
> upstream GCC approval, so I decided to go with LDC.
>
> Thus, is it possible to build an LDC crosscompiler that is 
> hosted on x86_64 Linux and targets i686/x86_64 Windows? If so, 
> how? I didn't find any information on the topic, people 
> appeareantly only ever want to target ARM (cell phones?), which 
> is not what I am interested in.
>
> Greetings
> Marvin
>
> [1]: http://mxe.cc

It should indeed be possible today. For LDC, MinGW was once 
supported but isn't anymore [although fixing that shouldn't be 
that hard]. We chose to focus on the 'native' path on Windows, 
centered around Microsoft's Visual C++ (its C runtime and its 
toolchain). So if you are fine with that, all you basically need 
is

a) an MS-compatible cross-linker (LLVM's lld),
b) druntime and Phobos compiled for Windows (you could just copy 
them from a Windows release package), and
c) a bunch of MS libs (WinSDK + Visual C++ ones)

while specifying something like `-mtriple=x86_64-pc-windows-msvc` 
in the LDC command line.
There's one catch though: you currently cannot specify an 
alternative external linker to be used for MSVC targets 
(`link.exe` is hardcoded), so you'd have to link manually or hack 
the LDC source. Generating static libs only is supported for any 
target starting with LDC 1.3.
Oh and lld isn't able to produce .pdb debuginfos at the moment. 
The plan is to integrate lld in LDC at some point, see 
https://github.com/ldc-developers/ldc/issues/2028.


More information about the digitalmars-d-ldc mailing list