www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.ldc - cross compiling linux -> windows

reply Oleg B <code.viator gmail.com> writes:
Hello. I'm try to cross build example program and get some error.

% ldc2 -mtriple=i686-w32-mingw32.static print_void_array.d
/home/obutko/workspace/ldc2-1.2.0-beta1-linux-x86_64/bin/../import/cor
/stdc/wchar_.d(80): Error: undefined identifier 'FILE'
...
/home/obutko/workspace/ldc2-1.2.0-beta1-linux-x86_64/bin/../import/cor
/stdc/stdio.d(830): Error: undefined identifier 'FILE'
...

and I don't understand how to fix it. If I add flag 
`-d-version=CRuntime_Windows` compiler fails with `Error: version 
identifier 'CRuntime_Microsoft' is reserved and cannot be set`

Maybe I have fundamentally wrong logic for doing this?
Mar 22 2017
next sibling parent reply kinke <noone nowhere.com> writes:
On Wednesday, 22 March 2017 at 12:35:16 UTC, Oleg B wrote:
 Hello. I'm try to cross build example program and get some 
 error.
Hi Oleg, MinGW isn't supported anymore, see release notes. Using the 32-bit MSVC triple `i686-pc-windows-msvc` should work.
Mar 22 2017
parent reply Oleg B <code.viator gmail.com> writes:
On Wednesday, 22 March 2017 at 13:08:07 UTC, kinke wrote:
 On Wednesday, 22 March 2017 at 12:35:16 UTC, Oleg B wrote:
 Hello. I'm try to cross build example program and get some 
 error.
Hi Oleg, MinGW isn't supported anymore, see release notes. Using the 32-bit MSVC triple `i686-pc-windows-msvc` should work.
Thanks, it works and now I get .obj output. ldc not support cross linking and I must use external tools for this?
Mar 22 2017
next sibling parent kinke <noone nowhere.com> writes:
On Wednesday, 22 March 2017 at 14:03:01 UTC, Oleg B wrote:
 On Wednesday, 22 March 2017 at 13:08:07 UTC, kinke wrote:
 On Wednesday, 22 March 2017 at 12:35:16 UTC, Oleg B wrote:
 Hello. I'm try to cross build example program and get some 
 error.
Hi Oleg, MinGW isn't supported anymore, see release notes. Using the 32-bit MSVC triple `i686-pc-windows-msvc` should work.
Thanks, it works and now I get .obj output. ldc not support cross linking and I must use external tools for this?
With LDC 1.3, you'll be able to at least generate static libs for any target. Linking executables and shared libraries is a different beast. If you can't/don't want to use the MS linker, you can use LLVM's LLD as cross-linker (works for MSVC targets, but can't emit .pdb debuginfos). You'll still need the MS libs though (Visual C runtime, WinSDK) and will have to play around with command-line options or environment variables to get it to work. If there's more interest wrt. cross-linking to Windows, I can integrate that into LDC 1.3 too, I've already prepared for this but then put it aside as cross-linking to non-Windows via an integrated LLD is non-trivial.
Mar 22 2017
prev sibling parent David Nadlinger <code klickverbot.at> writes:
On Wednesday, 22 March 2017 at 14:03:01 UTC, Oleg B wrote:
 Thanks, it works and now I get .obj output. ldc not support 
 cross linking and I must use external tools for this?
Well, in theory LDC doesn't care what linker it uses, so it supports cross-toolchains just fine. No matter how your (cross-)compiler is implemented, to create executables (or shared libraries) for a given target you will need the appropriate C runtime and so on to link against. In our case, this is taken care of by a (g)cc-compatible linker driver resp. link.exe for Windows. LDC doesn't rely on these "external tools" for cross-compilation any more than for creating native executables. Of course, in the case of Linux -> Windows, getting an equivalent link.exe in a Linux environment might be a bit challenging without resorting to tricks like linking in a VM. MinGW-w64 would be much easier to get working in this scenario. - David
Mar 22 2017
prev sibling parent reply Laeeth Isharc <laeethnospam nospam.laeeth.com> writes:
On Wednesday, 22 March 2017 at 12:35:16 UTC, Oleg B wrote:
 Hello. I'm try to cross build example program and get some 
 error.

 % ldc2 -mtriple=i686-w32-mingw32.static print_void_array.d
 /home/obutko/workspace/ldc2-1.2.0-beta1-linux-x86_64/bin/../import/cor
/stdc/wchar_.d(80): Error: undefined identifier 'FILE'
 ...
 /home/obutko/workspace/ldc2-1.2.0-beta1-linux-x86_64/bin/../import/cor
/stdc/stdio.d(830): Error: undefined identifier 'FILE'
 ...

 and I don't understand how to fix it. If I add flag 
 `-d-version=CRuntime_Windows` compiler fails with `Error: 
 version identifier 'CRuntime_Microsoft' is reserved and cannot 
 be set`

 Maybe I have fundamentally wrong logic for doing this?
fwiw dmd works under wine, last I checked. I have no idea about ldc.
Mar 22 2017
parent Oleg B <code.viator gmail.com> writes:
On Thursday, 23 March 2017 at 00:18:14 UTC, Laeeth Isharc wrote:
 fwiw dmd works under wine, last I checked.  I have no idea 
 about ldc.
dmd for win64 use m$ linker
Mar 23 2017