Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Want App, but Qt is creating a DLL instead



  • I am using Qt Creator 2.8.84 (3.0.0-rc1) for IDE only on Windows XP.
    The compiler is MinGW gcc (or g++) which was part of a Pelles C CodeBlocks installation.
    With this code, I get a bad .exe file.
    It looks like it is creating a dll, but I want an App.
    I know I should be linking with some libraries, but I don't know which ones or how to specify them.
    Should I be using CMake instead?

    # IFW32.pro
    
    CONFIG -= qt
    CONFIG -= app_bundle
    
    # To stop this error: undefined reference to 'WinMain@16'
    win32:QMAKE_LFLAGS += -shared
    
    SOURCES += main.c
    

    C Source file:

    // main.c
    
    #include <windows.h>
    
    int WINAPI wWinMain(HINSTANCE i, HINSTANCE pi, PWSTR szCmdLine, int cs)
    {
      MessageBoxW(NULL, szCmdLine, L"Win32 Test", MB_OK);
    
      return 0;
    }
    

    Output:

    Starting C:\Documents and Settings\Owner\A_IFW32\debug\IFW32.exe...
    Failed to start program. Path or permissions wrong?
    C:\Documents and Settings\Owner\A_IFW32\debug\IFW32.exe exited with code -1
    

    When I look in the .exe file with exeinfo.exe, I see:

    Characteristics            : 
     * The file is a dynamic-link library
    

  • Lifetime Qt Champion

    @harveyab

    To stop this error: undefined reference to 'WinMain@16'
    win32:QMAKE_LFLAGS += -shared

    This is your problem.

    You need to call your main function WinMain, not wWinMain



  • @aha_1980 Thank you. That fixed both problems, but printed garbage until I changed to MessageBoxA() and fixed the pointer sizes and types. Here is the final two files:

    IFW32.pro

    CONFIG -= qt
    CONFIG -= app_bundle
    SOURCES += main.c
    

    main.c

    #include <windows.h>
    int WINAPI WinMain(HINSTANCE i, HINSTANCE pi, LPSTR szCmdLine, int cs)
    {
      MessageBoxA(NULL, szCmdLine, "Win32 Prog", MB_OK);
      return 0;
    }
    

  • Moderators

    @harveyab said in Want App, but Qt is creating a DLL instead:

    CONFIG -= app_bundle
    

    You can also remove this line. It is only relevant on macOS, while you are targetting Windows only.


Log in to reply