Thread overview
Entry point errors when using LDC to compile Windows Subsystem module with -m32
Sep 20, 2018
spikespaz
Sep 20, 2018
kinke
Sep 20, 2018
kinke
September 20, 2018
I have a user having issues running my project on their 32-bit Windows install. I thought LDC2 compiled as 32-bit by default, but for some reason the errors persist for him regardless.

In attempt to resolve this, I am doing everything that requires 32-bit explicitly. I downloaded a known-good 32-bit libcurl.dll to distribute with the project, I added -m32 to all of the compile commands, added -L/SUBSYSTEM:WINDOWS etc.

When comping with the command below, I get linker errors saying that '/SUBSYSTEM:WINDOWS" isn't recognized and is ignored, and entry point must be defined. MSVCE linker fails with status 1221.

    ldc2 "source/launcher.d" "source/common.d" -of="build/$release/launcher.exe" \
        -m32 -O3 -ffast-math -release -g -L/SYBSYSTEM:WINDOWS

Compiling with the following command however works fine, but doesn't work on 32-bit systems.

    ldc2 "source/launcher.d" "source/common.d" -of="build/$release/launcher.exe" \
        -O3 -ffast-math -release -g

The issue stems from using 'extern (Windows) WinMain' as the entry point in the file. Any ideas how I can resolve this?

https://github.com/spikespaz/search-deflector/blob/master/source/launcher.d
https://github.com/spikespaz/search-deflector/blob/master/build.sh
September 20, 2018
On Thursday, 20 September 2018 at 20:48:50 UTC, spikespaz wrote:
> When comping with the command below, I get linker errors saying that '/SUBSYSTEM:WINDOWS" isn't recognized and is ignored

Then you're most likely accidentally using DMD's link.exe. When using a multilib LDC build on Win64 and cross-compiling to Win32, the IMO simplest way is to spawn a new naked cmd.exe shell with untainted PATH and let LDC detect the Visual Studio installation (and the 32-bit lib dirs).

On my system:

extern (Windows) int WinMain() { return 0; }

ldc2 -L/SUBSYSTEM:WINDOWS -m32:
error LNK2019: unresolved external symbol _WinMain@16 referenced in function "int __cdecl __scrt_common_main_seh(void)" (?__scrt_common_main_seh@@YAHXZ)

It's working with proper signature [1]:

extern (Windows) int WinMain(void* hInstance, void* hPrevInstance, void* lpCmdLine, int nCmdShow) { return 0; }

[1] https://msdn.microsoft.com/en-us/library/windows/desktop/ms633559(v=vs.85).aspx
September 20, 2018
On Thursday, 20 September 2018 at 20:48:50 UTC, spikespaz wrote:
> I downloaded a known-good 32-bit libcurl.dll to distribute with the project

I just figured that the multilib package is indeed missing a 32-bit libcurl.dll. It can be found in the bin dir of the win32 package (which btw is the one defaulting to generating 32-bit code).