Cross compiling for windows from linux

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Jan 25 16:02:28 UTC 2021


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


More information about the Digitalmars-d mailing list