MinGW, build GUI application with console

前端 未结 4 1723
情深已故
情深已故 2021-02-02 04:19

I\'m using MinGW to build my application on Windows. When compiling and linking, the option \"-mwindows\" is put in command line to have Win32 API functions.

To be more

4条回答
  •  终归单人心
    2021-02-02 04:54

    I have no evidence for this answer, only a bit of experiments that were successful. If I have a hello app, like this:

    #include 
    #include 
    
    int main(void)
    {
        puts("hi");
        MessageBox(NULL, "test", "test", NULL);
        GetStockObject(0);
        return 0;
    }
    

    I cannot compile it with -mconsole, because linker complains about GetStockObject. But when I add the necessary library with -lgdi32 switch on my command line, the app compiles and executes cleanly. Maybe this is the way to keep both console and gdi. This is the command line:

    gcc -mconsole test_gdi.c -lgdi32
    

提交回复
热议问题