Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. QtCreator - building a Win32 application with cmake [SOLVED]
Forum Update on Monday, May 27th 2025

QtCreator - building a Win32 application with cmake [SOLVED]

Scheduled Pinned Locked Moved Qt Creator and other tools
qtcreatorcmakewin32
2 Posts 1 Posters 5.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gustavo Ribeiro Croscato
    wrote on 11 Feb 2016, 21:57 last edited by Gustavo Ribeiro Croscato
    #1

    I'm trying to use QtCreator to build windows MFC applications using cmake.

    Currently I have a simple test application which is

    CMakeLists.txt

    project(Win32App)
    
    cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
    
    set(SRC
        main.cpp
    )
    
    set(HDR
    
    )
    
    set(RES)
    
    add_definitions(-DWIN32 -D_WINDOWS -D_UNICODE -DUNICODE)
    
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS,5.01")
    
    add_custom_target(${CMAKE_PROJECT}_HEADERS SOURCES ${HDR})
    
    add_executable(${CMAKE_PROJECT_NAME} ${SRC} ${RES})
    
    

    main.cpp

    #include <Windows.h>
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
        return 0;
    }
    

    it compiles okay in command line with cmake .. && cmake --build .
    In QtCreator occurs the following error MSVCRTD.lib(exe_main.obj) : error LNK2019: unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)

    To me it seems that the /SUBSYSTEM:WINDOWS,5.01 is being ignored during the QtCreator compilation process.

    Any ideias will be welcome.

    Thank you!

    1 Reply Last reply
    0
    • G Offline
      G Offline
      Gustavo Ribeiro Croscato
      wrote on 16 Feb 2016, 16:00 last edited by
      #2

      I found a solution. In case anyone has the same problem just add the following to you CMakeLists.txt:

      if(WIN32)
        set(GUI_TYPE WIN32)
      elseif(APPLE)
        set(GUI_TYPE MACOSX_BUNDLE)
      endif()
      

      then add

      ${GUI_TYPE}
      

      to your target.

      My CMakeLists.txt is now

      project(Win32App)
      
      cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
      
      if(WIN32)
        set(GUI_TYPE WIN32)
      elseif(APPLE)
        set(GUI_TYPE MACOSX_BUNDLE)
      endif()
      
      set(SRC
          main.cpp
      )
      
      set(HDR)
      
      set(RES)
      
      add_definitions(-DWIN32 -D_WINDOWS -D_UNICODE -DUNICODE)
      
      set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS,5.01")
      
      add_custom_target(${PROJECT_NAME}_HEADERS SOURCES ${HDR})
      
      add_executable(${CMAKE_PROJECT_NAME} ${GUI_TYPE} ${SRC} ${RES})
      
      1 Reply Last reply
      0

      2/2

      16 Feb 2016, 16:00

      • Login

      • Login or register to search.
      2 out of 2
      • First post
        2/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved