Cross compiling for windows from linux

Matthew monkeytonk115 at gmail.com
Mon Jan 25 13:34:40 UTC 2021


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


More information about the Digitalmars-d mailing list