www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Windows: SUBSYSTEM:WINDOWS, wWinMainCRTStartup and linker behavior

reply Alexander <roland.taverner gmail.com> writes:
So I added
```
"dflags": ["-L/SUBSYSTEM:WINDOWS", "-L/ENTRY:wWinMainCRTStartup"],
```
to `dub.json`, implemented `wWinMain()` as described at [D for 
Win32](https://wiki.dlang.org/D_for_Win32) (I think this needs to 
be updated for Unicode version, it's no sense to use non-Unicode 
if you are not programming for Windows 98) and everything was 
fine until I removed old `main()` function when decided the new 
one is good enough. After that seems linker just decided to drop 
all default dependencies including D runtime itself and I got a 
lot of `unresolved external` errors. It took me some time to 
figure out what caused this.
Is this linker behavior intentional? Now I have empty `main()` 
function to be able to build the app.
Jun 06
next sibling parent "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 07/06/2026 11:09 AM, Alexander wrote:
 So I added
 ```
 "dflags": ["-L/SUBSYSTEM:WINDOWS", "-L/ENTRY:wWinMainCRTStartup"],
 ```
 to `dub.json`, implemented `wWinMain()` as described at [D for Win32] 
 (https://wiki.dlang.org/D_for_Win32) (I think this needs to be updated 
 for Unicode version, it's no sense to use non-Unicode if you are not 
 programming for Windows 98) and everything was fine until I removed old 
 `main()` function when decided the new one is good enough. After that 
 seems linker just decided to drop all default dependencies including D 
 runtime itself and I got a lot of `unresolved external` errors. It took 
 me some time to figure out what caused this.
 Is this linker behavior intentional? Now I have empty `main()` function 
 to be able to build the app.
This may not be the linkers fault. main, WinMain, and DllMain are all recognized by dmd as entry points. It does not appear to support wWinMain, and that would be a bug.
Jun 06
prev sibling parent Adam D. Ruppe <destructionator gmail.com> writes:
On Saturday, 6 June 2026 at 23:09:06 UTC, Alexander wrote:
 So I added
 ```
 "dflags": ["-L/SUBSYSTEM:WINDOWS", 
 "-L/ENTRY:wWinMainCRTStartup"],
 ```
I suggest you just use a D main and do not attempt to write your own WinMain (or wWinMan). There's no need for that. You can use the (w)mainCRTStartup entry point. Not having a D main will make the compiler assume you're doing some betterC nonsense and you lose a bunch of conveniences. And you have to copy/paste druntime boilerplate. Not beneficial. Note that with OpenD this is all encapsulated in `--target=gui` command line option. You can even embed icons with `--icon=big.png,small.png` (sample filenames) and cross-compile from linux all with simple setup!
Jun 06