I am writing an application in D. It's compiled with the ldc2 compiler, using dub configuration (target type: executable). The compiled program creates a console window, which I do not need since the application uses a GUI framework. I need a way to prevent creating the console window.
The only other example I know with similar behaviour is when compiling C/C++ programs with mingw64-gcc, which has an -mwindows flag. I do not know anything similar for D programs. Neither dub configuration nor ldc compiler flags seem to do what I want. Does anyone know what to do? Even another compiler could work, if it at least does what I want.
When the application is opened from CMD or PowerShell, no additional console is opened. The problem only occurs when I start the application from the Windows GUI.
dub.json:
{
description (author etc.)
"targetType": "executable",
"platforms": [
"windows"
],
"dependencies": {
....
},
"versions" : [
....
],
"libs" : [
....
],
"dflags": [
"-m32",
"-static",
"-release"
]
}
compile command:
dub run --compiler=ldc2.exe
Solution:
add linker flags as follows in dub.json
"lflags":[
"-subsystem:windows",
"-entry:mainCRTStartup"
]
this removes the console poping up at program start, if the program is not run from another console. it also enables the usual d main (void main() etc.), NO need for the winmain entry point. (that can be used if you simply leave the entry flag out)
You need to add
"lflags": ["-Subsystem:Windows"]
to your dub.json
file to tell ldc to create a Window UI binary. The command line option to use is ldc2 -L=-Subsystem:Windows
.