www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Cross compiling for windows from linux

reply deadalnix <deadalnix gmail.com> writes:
Pretty much all is in the title.

I wanted to do this, and I don't even know where to begin. What 
are the options available?

Thanks in advance,

Amaury

PS: Glad to be back in D land. Hi everybody! I missed you!
Jan 21 2021
next sibling parent reply kinke <noone nowhere.com> writes:
The only option is LDC (GDC doesn't support Windows). See 
https://wiki.dlang.org/Cross-compiling_with_LDC.
Jan 21 2021
next sibling parent reply rikki cattermole <rikki cattermole.co.nz> writes:
On 22/01/2021 1:15 AM, kinke wrote:
 The only option is LDC (GDC doesn't support Windows). See 
 https://wiki.dlang.org/Cross-compiling_with_LDC.
dmd should also work via wine (note: 64bit should also work now thanks to mingw libs).
Jan 21 2021
parent reply deadalnix <deadalnix gmail.com> writes:
On Thursday, 21 January 2021 at 12:19:03 UTC, rikki cattermole 
wrote:
 On 22/01/2021 1:15 AM, kinke wrote:
 The only option is LDC (GDC doesn't support Windows). See 
 https://wiki.dlang.org/Cross-compiling_with_LDC.
dmd should also work via wine (note: 64bit should also work now thanks to mingw libs).
Is there an install guide somewhere? I don't have a GUI, so I can't use the installer.
Jan 21 2021
next sibling parent reply Rikki Cattermole <alphaglosined gmail.com> writes:
On Thursday, 21 January 2021 at 12:39:19 UTC, deadalnix wrote:
 Is there an install guide somewhere? I don't have a GUI, so I 
 can't use the installer.
No idea. I'd just use the zip file. http://downloads.dlang.org/releases/2.x/2.095.0/dmd.2.095.0.windows.zip
Jan 21 2021
parent reply deadalnix <deadalnix gmail.com> writes:
On Thursday, 21 January 2021 at 12:52:24 UTC, Rikki Cattermole 
wrote:
 On Thursday, 21 January 2021 at 12:39:19 UTC, deadalnix wrote:
 Is there an install guide somewhere? I don't have a GUI, so I 
 can't use the installer.
No idea. I'd just use the zip file. http://downloads.dlang.org/releases/2.x/2.095.0/dmd.2.095.0.windows.zip
Ok I'll figure it out. Thanks.
Jan 21 2021
parent Adam D. Ruppe <destructionator gmail.com> writes:
On Thursday, 21 January 2021 at 13:39:21 UTC, deadalnix wrote:
 Ok I'll figure it out. Thanks.
The beauty of dmd (and ldc's package too) from zip is that you don't have to install it. Just run it directly from the unzipped location. On my linux box, I have a little helper script called dmdw that just: exec wine /home/me/d/windows/dmd2/windows/bin/dmd.exe -m32mscoff $* So then I unzip dmd in ~/d/windows and boom it just works to `dmdw whatever.d` from there on.
Jan 21 2021
prev sibling parent Bastiaan Veelo <Bastiaan Veelo.net> writes:
On Thursday, 21 January 2021 at 12:39:19 UTC, deadalnix wrote:
 Is there an install guide somewhere? I don't have a GUI, so I 
 can't use the installer.
Have a look at install.sh: https://dlang.org/install.html — Bastiaan
Jan 21 2021
prev sibling parent deadalnix <deadalnix gmail.com> writes:
On Thursday, 21 January 2021 at 12:15:39 UTC, kinke wrote:
 The only option is LDC (GDC doesn't support Windows). See 
 https://wiki.dlang.org/Cross-compiling_with_LDC.
It seems like the most straightforward way to do it, I'll try that.
Jan 21 2021
prev sibling next sibling parent Paolo Invernizzi <paolo.invernizzi gmail.com> writes:
On Thursday, 21 January 2021 at 12:12:43 UTC, deadalnix wrote:
 Pretty much all is in the title.

 I wanted to do this, and I don't even know where to begin. What 
 are the options available?

 Thanks in advance,

 Amaury

 PS: Glad to be back in D land. Hi everybody! I missed you!
Welcome back! :-)
Jan 21 2021
prev sibling next sibling parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Thu, Jan 21, 2021 at 12:12:43PM +0000, deadalnix via Digitalmars-d wrote:
 Pretty much all is in the title.
 
 I wanted to do this, and I don't even know where to begin. What are
 the options available?
1) Install LDC for Linux. 2) Download and unpack LDC for Windows somewhere. 3) Edit ldc2.conf and add this block: "(i686|x86_64)-.*-windows.msvc": { switches = [ "-defaultlib=phobos2-ldc,druntime-ldc", "-link-defaultlib-shared=false", ]; lib-dirs = [ "/path/to/ldc/ldc2-1.24.0-windows-x64/lib", ]; }; 4) Compile your program with '-mtriple=x86_64-windows-msvc'. 5) Profit. ;-) [...]
 PS: Glad to be back in D land. Hi everybody! I missed you!
Awesome, glad to have you back! T -- It's amazing how careful choice of punctuation can leave you hanging:
Jan 21 2021
parent reply Matthew <monkeytonk115 gmail.com> writes:
On Thursday, 21 January 2021 at 16:20:12 UTC, H. S. Teoh wrote:
 On Thu, Jan 21, 2021 at 12:12:43PM +0000, deadalnix via 
 Digitalmars-d wrote:
 Pretty much all is in the title.
 
 I wanted to do this, and I don't even know where to begin. 
 What are the options available?
1) Install LDC for Linux. 2) Download and unpack LDC for Windows somewhere. 3) Edit ldc2.conf and add this block: "(i686|x86_64)-.*-windows.msvc": { switches = [ "-defaultlib=phobos2-ldc,druntime-ldc", "-link-defaultlib-shared=false", ]; lib-dirs = [ "/path/to/ldc/ldc2-1.24.0-windows-x64/lib", ]; }; 4) Compile your program with '-mtriple=x86_64-windows-msvc'. 5) Profit. ;-)
Hi, I am also trying to cross compile a windows exe from my linux host. I tried to follow the instructions from the wiki page [0], and your instructions are basically the same. I managed steps 1,2,3 but when compiling I get errors that the linker cannot find .lib files $ tail -n 13 /etc/ldc2.conf "(i686|x86_64)-.*-windows-msvc": { switches = [ "-defaultlib=phobos2-ldc,druntime-ldc", "-link-defaultlib-shared=false", ]; lib-dirs = [ "/home/matthew/Downloads/ldc2-1.24-0-windows-x64/lib", ]; }; $ cat hello.d import std.stdio; int main() { writeln("Hello world!"); return 0; } $ ldc -v -mtriple=x86_64-windows-msvc hello.d binary /usr/bin/ldc2 version 1.24.0 (DMD v2.094.1, LLVM 11.0.1) config /etc/ldc2.conf (x86_64-unknown-windows-msvc) predefs LDC all D_Version2 assert D_ModuleInfo D_Exceptions D_TypeInfo X86_64 D_InlineAsm_X86_64 D_HardFloat LittleEndi an D_LP64 D_PIC Windows Win64 CRuntime_Microsoft CppRuntime_Microsoft LDC_LLVM_1100 parse hello importall hello import object (/usr/include/dlang/ldc/object.d) import core.internal.hash (/usr/include/dlang/ldc/core/internal/hash.d) import core.internal.traits (/usr/include/dlang/ldc/core/internal/traits.d) import core.internal.convert (/usr/include/dlang/ldc/core/internal/convert.d) import core.internal.entrypoint (/usr/include/dlang/ldc/core/internal/entrypoint.d) import core.internal.array.appending (/usr/include/dlang/ldc/core/internal/array/appending.d) import core.internal.array.comparison (/usr/include/dlang/ldc/core/internal/array/comparison.d) import core.internal.array.equality (/usr/include/dlang/ldc/core/internal/array/equality.d) import core.internal.array.casting (/usr/include/dlang/ldc/core/internal/array/casting.d) import core.internal.array.concatenation (/usr/include/dlang/ldc/core/internal/array/concatenation.d) import core.internal.array.construction (/usr/include/dlang/ldc/core/internal/array/construction.d) import core.internal.array.capacity (/usr/include/dlang/ldc/core/internal/array/capacity.d) import core.internal.dassert (/usr/include/dlang/ldc/core/internal/dassert.d) import core.atomic (/usr/include/dlang/ldc/core/atomic.d) import core.internal.attributes (/usr/include/dlang/ldc/core/internal/attributes.d) import core.internal.atomic (/usr/include/dlang/ldc/core/internal/atomic.d) import ldc.intrinsics (/usr/include/dlang/ldc/ldc/intrinsics.di) import core.internal.destruction (/usr/include/dlang/ldc/core/internal/destruction.d) import core.internal.moving (/usr/include/dlang/ldc/core/internal/moving.d) import core.internal.postblit (/usr/include/dlang/ldc/core/internal/postblit.d) import core.internal.switch_ (/usr/include/dlang/ldc/core/internal/switch_.d) import std.stdio (/usr/include/dlang/ldc/std/stdio.d) import core.stdc.stddef (/usr/include/dlang/ldc/core/stdc/stddef.d) import std.algorithm.mutation (/usr/include/dlang/ldc/std/algorithm/mutation.d) import std.traits (/usr/include/dlang/ldc/std/traits.d) import std.meta (/usr/include/dlang/ldc/std/meta.d) import std.range.primitives (/usr/include/dlang/ldc/std/range/primitives.d) import std.functional (/usr/include/dlang/ldc/std/functional.d) import std.typecons (/usr/include/dlang/ldc/std/typecons.d) import std.format (/usr/include/dlang/ldc/std/format.d) import core.vararg (/usr/include/dlang/ldc/core/vararg.d) import core.stdc.stdarg (/usr/include/dlang/ldc/core/stdc/stdarg.d) import std.exception (/usr/include/dlang/ldc/std/exception.d) import std.internal.attributes (/usr/include/dlang/ldc/std/internal/attributes.d) import core.sys.windows.basetsd (/usr/include/dlang/ldc/core/sys/windows/basetsd.d) import core.stdc.stdio (/usr/include/dlang/ldc/core/stdc/stdio.d) import core.stdc.stdint (/usr/include/dlang/ldc/core/stdc/stdint.d) import core.stdc.config (/usr/include/dlang/ldc/core/stdc/config.d) import core.stdc.signal (/usr/include/dlang/ldc/core/stdc/signal.d) import core.stdc.wchar_ (/usr/include/dlang/ldc/core/stdc/wchar_.d) import core.stdc.time (/usr/include/dlang/ldc/core/stdc/time.d) import core.sys.windows.stdc.time (/usr/include/dlang/ldc/core/sys/windows/stdc/time.d) semantic hello import core.sys.windows.winbase (/usr/include/dlang/ldc/core/sys/windows/winbase.d) import core.sys.windows.windef (/usr/include/dlang/ldc/core/sys/windows/windef.d) import core.sys.windows.winnt (/usr/include/dlang/ldc/core/sys/windows/winnt.d) import core.sys.windows.winerror (/usr/include/dlang/ldc/core/sys/windows/winerror.d) import core.sys.windows.w32api (/usr/include/dlang/ldc/core/sys/windows/w32api.d) import core.sys.windows.basetyps (/usr/include/dlang/ldc/core/sys/windows/basetyps.d) import core.sys.windows.winver (/usr/include/dlang/ldc/core/sys/windows/winver.d) import core.sys.windows.sdkddkver (/usr/include/dlang/ldc/core/sys/windows/sdkddkver.d) library kernel32 library version import core.stdc.errno (/usr/include/dlang/ldc/core/stdc/errno.d) entry main hello.d semantic2 hello semantic3 hello import std.utf (/usr/include/dlang/ldc/std/utf.d) import core.exception (/usr/include/dlang/ldc/core/exception.d) import core.internal.string (/usr/include/dlang/ldc/core/internal/string.d) import std.algorithm.comparison (/usr/include/dlang/ldc/std/algorithm/comparison.d) import core.stdc.string (/usr/include/dlang/ldc/core/stdc/string.d) GC stats 0M used, 5M free, 5M total code hello /usr/bin/lld-link /NOLOGO /OPT:REF /OPT:ICF /DEFAULTLIB:vcruntime140 /OUT:hello.exe hello.obj /LIBPATH:/home/matthew/Downloads/ldc2-1.24-0-windows-x64/lib /LIBPATH:/home/matthew/Downloads/ldc2-1.24-0-windows-x64/lib/mingw /LIBPATH:/home/matthew/Downloads/ldc2-1.24-0-windows-x64/lib/mingw phobos2-ldc.lib druntime-ldc.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib oldnames.lib legacy_stdio_definitions.lib lld-link: error: could not open 'phobos2-ldc.lib': No such file or directory lld-link: error: could not open 'druntime-ldc.lib': No such file or directory lld-link: error: could not open 'kernel32.lib': No such file or directory lld-link: error: could not open 'user32.lib': No such file or directory lld-link: error: could not open 'gdi32.lib': No such file or directory lld-link: error: could not open 'winspool.lib': No such file or directory lld-link: error: could not open 'shell32.lib': No such file or directory lld-link: error: could not open 'ole32.lib': No such file or directory lld-link: error: could not open 'oleaut32.lib': No such file or directory lld-link: error: could not open 'uuid.lib': No such file or directory lld-link: error: could not open 'comdlg32.lib': No such file or directory lld-link: error: could not open 'advapi32.lib': No such file or directory lld-link: error: could not open 'oldnames.lib': No such file or directory lld-link: error: could not open 'legacy_stdio_definitions.lib': No such file or directory lld-link: error: could not open 'vcruntime140.lib': No such file or directory Error: /usr/bin/lld-link failed with status: 1 I have checked that the path /home/matthew/Downloads/ldc2-1.24-0-windows-x64/lib does actually contain phobos2-ldc.lib and druntime2-ldc.lib I'm hoping there is something really obvious that I missed but I can't seem to figure it out. Any help would be appreciated. [0] https://wiki.dlang.org/Cross-compiling_with_LDC
Jan 25 2021
parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Mon, Jan 25, 2021 at 01:34:40PM +0000, Matthew via Digitalmars-d wrote:
[...]
 lld-link: error: could not open 'phobos2-ldc.lib': No such file or directory
 lld-link: error: could not open 'druntime-ldc.lib': No such file or directory
 lld-link: error: could not open 'kernel32.lib': No such file or directory
 lld-link: error: could not open 'user32.lib': No such file or directory
 lld-link: error: could not open 'gdi32.lib': No such file or directory
 lld-link: error: could not open 'winspool.lib': No such file or directory
 lld-link: error: could not open 'shell32.lib': No such file or directory
 lld-link: error: could not open 'ole32.lib': No such file or directory
 lld-link: error: could not open 'oleaut32.lib': No such file or directory
 lld-link: error: could not open 'uuid.lib': No such file or directory
 lld-link: error: could not open 'comdlg32.lib': No such file or directory
 lld-link: error: could not open 'advapi32.lib': No such file or directory
 lld-link: error: could not open 'oldnames.lib': No such file or directory
 lld-link: error: could not open 'legacy_stdio_definitions.lib': No such file
or directory
 lld-link: error: could not open 'vcruntime140.lib': No such file or directory
 Error: /usr/bin/lld-link failed with status: 1
 
 I have checked that the path
 /home/matthew/Downloads/ldc2-1.24-0-windows-x64/lib does actually contain
 phobos2-ldc.lib and druntime2-ldc.lib
That's very odd. If those files exist and your paths are correct, then it should work. Are you sure your ldc2.conf block is correct? You might want to try retyping the paths in ldc2.conf again manually just in case there was some copy-n-paste munging that sometimes happens. Also, which version of LDC2 for Windows did you download? The one I'm using is ldc2-1.24.0-windows-x64.7z (for compiling 64-bit applications; there's also an *-x86* version for compiling 32-bit Windows applications; for that you have to use a different triple and different ldc2.conf block). Just for reference, my exact setup is: - Download: https://github.com/ldc-developers/ldc/releases/download/v1.24.0/ldc2-1.24.0-linux-x86_64.tar.xz https://github.com/ldc-developers/ldc/releases/download/v1.24.0/ldc2-1.24.0-windows-x86.7z - Unpack to /usr/src/d/ldc/, which should produce: /usr/src/d/ldc/ldc2-1.24.0-linux-x86_64/{bin,etc,import,lib,...} /usr/src/d/ldc/ldc2-1.24.0-windows-x64/{bin,etc,import,lib,...} - Edit /usr/src/d/ldc/ldc2-1.24.0-linux-x86_64/etc/ldc2.conf and append this block: "(i686|x86_64)-.*-windows.msvc": { switches = [ "-defaultlib=phobos2-ldc,druntime-ldc", "-link-defaultlib-shared=false", ]; lib-dirs = [ "/usr/src/d/ldc/ldc2-1.24.0-windows-x64/lib", ]; }; - Then I symlink /usr/src/d/ldc/ldc2-1.24.0-linux-x86_64/bin/ldc2 to $HOME/bin/ldc2, and run it as: $HOME/bin/ldc2 -mtriple=x86_64-windows-msvc source.d -of=program.exe (Note that ldc2 should point to the *Linux* version of LDC2.) This produces program.exe which can be run with Wine or copied to a Windows machine and run there. T -- If Java had true garbage collection, most programs would delete themselves upon execution. -- Robert Sewell
Jan 25 2021
parent reply Matthew <monkeytonk115 gmail.com> writes:
Thank you so much!

Using the two ldc extracted from the tarballs on github worked, I 
had ldc2 installed via pacman before, maybe something I did 
previously messed something up. I should probably reinstall this 
system at some point...
Jan 25 2021
parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Mon, Jan 25, 2021 at 09:33:19PM +0000, Matthew via Digitalmars-d wrote:
 Thank you so much!
 
 Using the two ldc extracted from the tarballs on github worked, I had
 ldc2 installed via pacman before, maybe something I did previously
 messed something up. I should probably reinstall this system at some
 point...
Yeah, generally I try to stick to using tarballs/zips from the same source. Mixing libraries from two versions of the same compiler, or the same version but compiled by two different sources (probably with subtle differences), seems to be recipe for frustration, based on prior experience of similar situations. T -- What doesn't kill me makes me stranger.
Jan 25 2021
prev sibling next sibling parent reply RazvanN <razvan.nitu1305 gmail.com> writes:
On Thursday, 21 January 2021 at 12:12:43 UTC, deadalnix wrote:
 Pretty much all is in the title.

 I wanted to do this, and I don't even know where to begin. What 
 are the options available?

 Thanks in advance,

 Amaury

 PS: Glad to be back in D land. Hi everybody! I missed you!
Hi Amaury! Glad to have you back! There is this install guide [1] which has a section "Building dmd for Windows on Linux". It is a guide to install dmd for windows on linux using wine. Cheers, RazvanN [1] https://wiki.dlang.org/Building_under_Posix
Jan 21 2021
parent reply deadalnix <deadalnix gmail.com> writes:
On Friday, 22 January 2021 at 07:52:24 UTC, RazvanN wrote:
 Hi Amaury! Glad to have you back!

 There is this install guide [1] which has a section "Building 
 dmd for Windows on Linux". It is a guide to install dmd for 
 windows on linux using wine.

 Cheers,
 RazvanN

 [1] https://wiki.dlang.org/Building_under_Posix
Hey, I tried that, but I have no GUI, which the installer require. I may end up just running X on another machine and run it this way, but I was hoping for a simpler way.
Jan 22 2021
next sibling parent Adam D. Ruppe <destructionator gmail.com> writes:
On Saturday, 23 January 2021 at 00:09:17 UTC, deadalnix wrote:
 Hey, I tried that, but I have no GUI, which the installer 
 require.
You don't need an installer. Just unzip and run in place with wine. wine works fine without X running too.
Jan 22 2021
prev sibling parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Sat, Jan 23, 2021 at 12:09:17AM +0000, deadalnix via Digitalmars-d wrote:
 On Friday, 22 January 2021 at 07:52:24 UTC, RazvanN wrote:
[...]
 [1] https://wiki.dlang.org/Building_under_Posix
Hey, I tried that, but I have no GUI, which the installer require. I may end up just running X on another machine and run it this way, but I was hoping for a simpler way.
Did you see the steps I posted? No need of any GUI, just download and install LDC for Linux and download and unpack LDC for Windows (both from here: https://github.com/ldc-developers/ldc/releases -- just download the tarball/zip and unpack them, no need for any installers), edit ldc2.conf, and you can start cross-compiling right away. It's what I've been doing for the past year for one of my projects. :-D The LDC folk have done a really awesome job at making Linux -> Windows cross-compilation so painless. T -- There are four kinds of lies: lies, damn lies, and statistics.
Jan 22 2021
prev sibling next sibling parent Walter Bright <newshound2 digitalmars.com> writes:
On 1/21/2021 4:12 AM, deadalnix wrote:
 Pretty much all is in the title.
 
 I wanted to do this, and I don't even know where to begin. What are the
options 
 available?
 
 Thanks in advance,
 
 Amaury
 
 PS: Glad to be back in D land. Hi everybody! I missed you!
We missed you too! Good to see you back. As for cross compiling, I've recently made some progress getting DMD to this state (Mathias has done some work on it, too) but we're not there yet. At the moment, using a windows emulator on Linux should work.
Jan 22 2021
prev sibling parent Jacob Carlborg <doob me.com> writes:
On 2021-01-21 13:12, deadalnix wrote:
 Pretty much all is in the title.
 
 I wanted to do this, and I don't even know where to begin. What are the 
 options available?
Here's a Dockerfile that sets up everything [1]. As you can see it's quite old. This is before LDC shipped with the MinGW libraries. The Dockerfile pulls these from someone's Dropbox account [2]. This should not be necessary anymore. [1] https://github.com/jacob-carlborg/docker-ldc-windows/blob/master/Dockerfile [2] https://github.com/jacob-carlborg/docker-ldc-windows/blob/61e01d00bd4ac45fae65c66d00db86d8afdad2fd/Dockerfile#L12 -- /Jacob Carlborg
Jan 23 2021