digitalmars.D.ldc - Having trouble cross-compiling from linux to windows
- TheZipCreator (48/120) Jan 14 2023 I've installed ldc2 for linux and am now trying to compile for
- ryuukk_ (17/17) Jan 14 2023 If i remember correctly, you need to make sure you have
- TheZipCreator (2/19) Jan 14 2023 I've added that and I still get the same errors.
- Sergey (32/32) Jan 14 2023 I don't have ability to test it, but try this How-To:
- TheZipCreator (2/22) Jan 14 2023 this worked (or at least the executable runs under wine)! thanks
- TheZipCreator (11/29) Jan 14 2023 actually, nevermind. I tried to compile something more
- kinke (8/13) Jan 15 2023 Not sure if that's the problem, but as mentioned on
- TheZipCreator (4/18) Jan 15 2023 This did appear to be the issue. I reinstalled ldc2 from the same
I've installed ldc2 for linux and am now trying to compile for
windows. I downloaded the windows release as well and put the
libs into the libs folder of the linux version. I'm currently
trying to compile a simple test application:
```d
import std.stdio;
void main() {
writeln("Hello, World!");
}
```
with the following compiler arguments:
`ldc2 hello.d --mtriple x86_64-windows-msvc`
but I get a linker error (with `-c` it compiles just fine, but I
need to produce an executable so that won't work.)
Here's the output the compiler gives me:
```
lld-link: error: <root>: undefined symbol: wmainCRTStartup
lld-link: error: undefined symbol:
_D3std5stdio13trustedStdoutFNdNeZSQBgQBf4File
referenced by
hello.obj:(_D3std5stdio__T7writelnTAyaZQnFNfQjZv)
lld-link: error: undefined symbol:
_D3std5stdio4File17lockingTextWriterMFNfZSQBoQBnQBk17LockingTextWriter
referenced by
hello.obj:(_D3std5stdio__T7writelnTAyaZQnFNfQjZv)
lld-link: error: undefined symbol: _D3std5stdio4File6__dtorMFNfZv
referenced by
hello.obj:(_D3std5stdio__T7writelnTAyaZQnFNfQjZv)
referenced by
hello.obj:(?dtor$7 ?0?_D3std5stdio__T7writelnTAyaZQnFNfQjZv 4HA)
lld-link: error: undefined symbol:
_D3std5stdio4File17LockingTextWriter10__aggrDtorMFNeZv
referenced by
hello.obj:(_D3std5stdio__T7writelnTAyaZQnFNfQjZv)
referenced by
hello.obj:(?dtor$4 ?0?_D3std5stdio__T7writelnTAyaZQnFNfQjZv 4HA)
lld-link: error: undefined symbol: __CxxFrameHandler3
referenced by hello.obj:(.xdata)
lld-link: error: undefined symbol: _d_enter_cleanup
referenced by
hello.obj:(?dtor$4 ?0?_D3std5stdio__T7writelnTAyaZQnFNfQjZv 4HA)
referenced by
hello.obj:(?dtor$7 ?0?_D3std5stdio__T7writelnTAyaZQnFNfQjZv 4HA)
lld-link: error: undefined symbol: _d_leave_cleanup
referenced by
hello.obj:(?dtor$4 ?0?_D3std5stdio__T7writelnTAyaZQnFNfQjZv 4HA)
referenced by
hello.obj:(?dtor$7 ?0?_D3std5stdio__T7writelnTAyaZQnFNfQjZv 4HA)
lld-link: error: undefined symbol: _d_wrun_main
referenced by hello.obj:(wmain)
lld-link: error: undefined symbol:
_D3std5stdio4File17LockingTextWriter26highSurrogateShouldBeEmptyMFNfZv
referenced by
hello.obj:(_D3std5stdio4File17LockingTextWriter__T3putTaZQhMFNfaZv)
referenced by
hello.obj:(_D3std5stdio4File17LockingTextWriter__T3putTyaZQiMFNfyaZv)
lld-link: error: undefined symbol:
_D3std5stdio4File17LockingTextWriter7handle_MFNdNeZPS4core4stdcQCf6_iobuf
referenced by
hello.obj:(_D3std5stdio4File17LockingTextWriter__T3putTaZQhMFNfaZv)
referenced by
hello.obj:(_D3std5stdio4File17LockingTextWriter__T3putTaZQhMFNfaZv)
referenced by
hello.obj:(_D3std5stdio4File17LockingTextWriter__T3putTaZQhMFNfaZv)
referenced 3 more times
lld-link: error: undefined symbol: _fputc_nolock
referenced by
hello.obj:(_D3std5stdio4File17LockingTextWriter__T3putTaZQhMFNfaZv)
referenced by
hello.obj:(_D3std5stdio4File17LockingTextWriter__T3putTyaZQiMFNfyaZv)
lld-link: error: undefined symbol: _fputwc_nolock
referenced by
hello.obj:(_D3std5stdio4File17LockingTextWriter__T3putTaZQhMFNfaZv)
referenced by
hello.obj:(_D3std5stdio4File17LockingTextWriter__T3putTaZQhMFNfaZv)
referenced by
hello.obj:(_D3std5stdio4File17LockingTextWriter__T3putTyaZQiMFNfyaZv)
referenced 1 more times
lld-link: error: undefined symbol: _d_arraybounds_index
referenced by
hello.obj:(_D3std5stdio4File17LockingTextWriter__T3putTaZQhMFNfaZv)
referenced by
hello.obj:(_D3std5stdio4File17LockingTextWriter__T3putTaZQhMFNfaZv)
referenced by
hello.obj:(_D3std5stdio4File17LockingTextWriter__T3putTyaZQiMFNfyaZv)
referenced 8 more times
lld-link: error: undefined symbol: _d_arraybounds_slice
referenced by
hello.obj:(_D3std5stdio4File17LockingTextWriter__T3putTaZQhMFNfaZv)
referenced by
hello.obj:(_D3std5stdio4File17LockingTextWriter__T3putTyaZQiMFNfyaZv)
referenced by
hello.obj:(_D3std3utf__T11decodeFrontVEQBa8typecons__T4FlagVAyaa19_7573655265706c6163656d656e744463686172ZQCai0TAaZQDnFNaNeMKQnJmZw)
referenced 2 more times
lld-link: error: undefined symbol: fwrite
referenced by
hello.obj:(_D3std5stdio__T13trustedFwriteTaZQsFNbNiNePOS4core4stdcQBx6_iobufxAaZm)
lld-link: error: undefined symbol: ClassInfo for
std.exception.ErrnoException
referenced by
hello.obj:(_D3std9exception__T7bailOutHTCQBcQBb14ErrnoExceptionZQBiFNfAyamMAxaZNn)
lld-link: error: undefined symbol: _d_allocclass
referenced by
hello.obj:(_D3std9exception__T7bailOutHTCQBcQBb14ErrnoExceptionZQBiFNfAyamMAxaZNn)
referenced by
hello.obj:(_D3std3utf__T10decodeImplVbi1VEQBd8typecons__T4FlagVAyaa19_7573655265706c6163656d656e744463686172ZQCai0TAxaZQDrFQiKmZ__T9exceptionTQBbZQpFNaNbNfQBoQDrZCQFuQFt12UTFException)
referenced by
hello.obj:(_D3std3utf__T13_utfExceptionVEQBc8typecons__T4FlagVAyaa19_7573655265706c6163656d656e744463686172ZQCai0ZQDmFNaNfQCiwZw)
lld-link: error: undefined symbol: vtable for
std.exception.ErrnoException
referenced by
hello.obj:(_D3std9exception__T7bailOutHTCQBcQBb14ErrnoExceptionZQBiFNfAyamMAxaZNn)
lld-link: error: undefined symbol: initializer for
std.exception.ErrnoException
referenced by
hello.obj:(_D3std9exception__T7bailOutHTCQBcQBb14ErrnoExceptionZQBiFNfAyamMAxaZNn)
lld-link: error: too many errors emitted, stopping now (use
/errorlimit:0 to see all errors)
Error: linking with LLD failed
```
Jan 14 2023
If i remember correctly, you need to make sure you have
```
"x86_64-.*-windows-msvc":
{
switches = [
"-defaultlib=phobos2-ldc,druntime-ldc",
];
lib-dirs = [
"%%ldcbinarypath%%/../lib-win64",
];
};
```
in ``$LDC_PATH/etc/ldc2.conf ``
Here is how dscanner is doing it:
https://github.com/dlang-community/D-Scanner/blob/master/setup-ldc-windows.sh
I wonder why they need to do all of that, it should work out of
the box.. that's weird
Jan 14 2023
On Saturday, 14 January 2023 at 20:24:06 UTC, ryuukk_ wrote:
If i remember correctly, you need to make sure you have
```
"x86_64-.*-windows-msvc":
{
switches = [
"-defaultlib=phobos2-ldc,druntime-ldc",
];
lib-dirs = [
"%%ldcbinarypath%%/../lib-win64",
];
};
```
in ``$LDC_PATH/etc/ldc2.conf ``
Here is how dscanner is doing it:
https://github.com/dlang-community/D-Scanner/blob/master/setup-ldc-windows.sh
I wonder why they need to do all of that, it should work out of
the box.. that's weird
I've added that and I still get the same errors.
Jan 14 2023
I don't have ability to test it, but try this How-To:
* download LDC for Linux
* download LDC for Windows (multilib)
* extract LDC for Linux somewhere - it will be $LDC_PATH
* add to $PATH : $LDC_PATH/bin
* extract LDC for Windows and move folders lib32 and lib64 to
<LDC_PATH>/win-lib32 and <LDC_PATH>/win_lib64
* add rows below to the $LDC_PATH/etc/ldc2.conf:
```bash
"i[3-6]86-.*-windows-msvc":
{
switches = [
"-defaultlib=phobos2-ldc,druntime-ldc",
"-link-defaultlib-shared=false",
];
lib-dirs = [
"%%ldcbinarypath%%/../win-lib32",
];
};
"x86_64-.*-windows-msvc":
{
switches = [
"-defaultlib=phobos2-ldc,druntime-ldc",
"-link-defaultlib-shared=false",
];
lib-dirs = [
"%%ldcbinarypath%%/../win-lib64",
];
};
```
* to build use
```dub build --arch=x86_64-pc-windows-msvc```
Jan 14 2023
On Saturday, 14 January 2023 at 22:16:35 UTC, Sergey wrote:
I don't have ability to test it, but try this How-To:
* download LDC for Linux
* download LDC for Windows (multilib)
* extract LDC for Linux somewhere - it will be $LDC_PATH
* add to $PATH : $LDC_PATH/bin
* extract LDC for Windows and move folders lib32 and lib64 to
<LDC_PATH>/win-lib32 and <LDC_PATH>/win_lib64
* add rows below to the $LDC_PATH/etc/ldc2.conf:
```bash
"i[3-6]86-.*-windows-msvc":
{
switches = [
"-defaultlib=phobos2-ldc,druntime-ldc",
"-link-defaultlib-shared=false",
];
lib-dirs = [
"%%ldcbinarypath%%/../win-lib32",
];
};
[...]
this worked (or at least the executable runs under wine)! thanks
Jan 14 2023
actually, nevermind. I tried to compile something more substantial (my terminal game, [qonquest](https://github.com/TheZipCreator/qonquest)) as a test and I got the following errors: ``` lld-link: error: undefined symbol: _D3std4file8DirEntry4nameMxFNaNbNdNjNlNfZAyalld-link: error: undefined symbol: _D6object9Throwable4nextMNgFNaNbNdNiNjNlNfZNgCQBsQBoreferenced by /home/z/code/d/qonquest/source/script.d:236 .dub/build/application-debug-windows-x86_64-ldc_v1.30.0-git-501c657-B35CDD9344888E5E741CE71FFBE20530/qonquest.obj:(_D6script11loadScriptsFAyaPS4arsd8terminal8TerminalZv) referenced by /home/z/code/d/qonquest/source/saveload.d:82 .dub/build/application-debug-windows-x86_64-ldc_v1.30.0-git-501c657-B35CDD9344888E5E741CE71FFBE20530/qonquest.obj:(_D8saveload8saveListFZAya) referenced by /home/z/.dub/packages/arsd-official-10.9.8/arsd-official/terminal.d:7391 arsd-official_terminal.lib(arsd.terminal.obj):(_D4arsd8terminal14FileLineGetter11tabCompleteMFIAwIQdZAAya)``` which both appear to be phobos/druntime thingsreferenced by .dub/build/application-debug-windows-x86_64-ldc_v1.30.0-git-501c657-B35CDD9344888E5E741CE71FFBE20530/ onquest.obj:(vtable for script.ScriptException) referenced by .dub/build/application-debug-windows-x86_64-ldc_v1.30.0-git-501c657-B35CDD9344888E5E741CE71FFBE20530/ onquest.obj:(vtable for app.CommandException) referenced by arsd-official_terminal.lib(arsd.terminal.obj):(vtable for arsd.terminal.UserInterruptionException) referenced 1 more times
Jan 14 2023
On Saturday, 14 January 2023 at 22:54:13 UTC, TheZipCreator wrote:actually, nevermind. I tried to compile something more substantial (my terminal game, [qonquest](https://github.com/TheZipCreator/qonquest)) as a test and I got the following errors: [...]Not sure if that's the problem, but as mentioned on https://wiki.dlang.org/Cross-compiling_with_LDC, it is absolutely crucial that the Windows libs are copied from a Windows package *of the same version as your host LDC* (so that the bundled importable .d files match the prebuilt libs). You seem to be using a CI build (`…-git-501c657`), so the Windows package needs to be from the same CI build.
Jan 15 2023
On Sunday, 15 January 2023 at 11:21:46 UTC, kinke wrote:On Saturday, 14 January 2023 at 22:54:13 UTC, TheZipCreator wrote:This did appear to be the issue. I reinstalled ldc2 from the same release as where I got the windows libs and now it works perfectly.actually, nevermind. I tried to compile something more substantial (my terminal game, [qonquest](https://github.com/TheZipCreator/qonquest)) as a test and I got the following errors: [...]Not sure if that's the problem, but as mentioned on https://wiki.dlang.org/Cross-compiling_with_LDC, it is absolutely crucial that the Windows libs are copied from a Windows package *of the same version as your host LDC* (so that the bundled importable .d files match the prebuilt libs). You seem to be using a CI build (`…-git-501c657`), so the Windows package needs to be from the same CI build.
Jan 15 2023









TheZipCreator <thezipcreator protonmail.com> 