1

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)

4

1 回答 1

1

您需要添加

"lflags": ["-Subsystem:Windows"]

到你的dub.json文件告诉 ldc 创建一个 Window UI 二进制文件。要使用的命令行选项是ldc2 -L=-Subsystem:Windows.

于 2017-08-29T05:10:16.160 回答