Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Unable to compile using Mingwx64 on windows, Command line option error

Unable to compile using Mingwx64 on windows, Command line option error

Scheduled Pinned Locked Moved Unsolved General and Desktop
mingw64
12 Posts 3 Posters 2.1k 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.
  • VRoninV Offline
    VRoninV Offline
    VRonin
    wrote on last edited by
    #2

    Are you trying to compile your project or the Qt library itself?
    Can you post your CMakeLists?

    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
    ~Napoleon Bonaparte

    On a crusade to banish setIndexWidget() from the holy land of Qt

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Dariusz
      wrote on last edited by Dariusz
      #3

      @VRonin Hey I've simply changed my compiler from msvc to mingw64. Im trying to run my app. Using precompiled mingw64 binaries from qt installer. I tried using both mingw shipped ith QT, and latest official one. Both have issues

      Here is most of my Qt related cmake code > it currently "has issues" with dlls given some of them don't exist under mingw, but thats to fix after I get it to build without the darn error :- (

      set(sp "-----  ")
      set(QT_PATH "C:/Qt/6.1.2/")
      if (MSVC)
          # warning level 4 and all warnings as errors
          #add_compile_options(/W4 /WX)
          set(QT_PATH ${QT_PATH}msvc2019_64)
          message(\n ${sp} "IM IN MSVC")
      else ()
          # lots of warnings and all warnings as errors
          message(\n ${sp} "IM NOT IN MSVC")
          #add_compile_options(-Wall -Wextra -pedantic -Werror)
          add_compile_options(-Wno-error=unknown-warning)
          #set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
          #set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
          #set(CMAKE_C_COMPILER_WORKS 1)
          set(QT_PATH ${QT_PATH}mingw81_64)
      endif ()
      
      
      
      set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${QT_PATH})
      
      set(LIB_MODE STATIC)
      set(GLOBAL_ROOT ${CMAKE_SOURCE_DIR})
      
      set(CMAKE_AUTOMOC ON)
      set(CMAKE_AUTORCC ON)
      set(CMAKE_AUTOUIC ON)
      
      set(QT_USE_QTGUI TRUE)
      set(QT_USE_QTXML TRUE)
      
      set(QT_VERSION 6)
      set(REQUIRED_LIBS Core Widgets Gui Network OpenGL)
      set(REQUIRED_LIBS_QUALIFIED Qt6::Core Qt6::Widgets Qt6::Gui Qt6::Network Qt6::OpenGL)
      ADD_DEFINITIONS(-DQT_NO_KEYWORDS)
      ADD_DEFINITIONS(${QT_DEFINITIONS} -DQT_MESSAGELOGCONTEXT)
      ADD_DEFINITIONS(-D_USE_MATH_DEFINES)
      
      message("\n\n")
      message(${sp} "CORE CMAKE IMPORT")
      message(${sp} "Global Root : " ${GLOBAL_ROOT})
      message(${sp} "QT          : " ${QT_PATH})
      message(${sp} "")
      message(${sp} "FindPackage QT : " "Qt${QT_VERSION}" " COMPONENTS : " "${REQUIRED_LIBS} " "REQUIRED")
      message("\n\n")
      
      find_package(Qt${QT_VERSION} COMPONENTS ${REQUIRED_LIBS} REQUIRED)
      
      
      message(\n\n ${sp} "Qt Prep\n")
      # Import QT dlls/etc
      if (WIN32)
          set(DEBUG_SUFFIX)
          if (CMAKE_BUILD_TYPE MATCHES "Debug")
              set(DEBUG_SUFFIX "d")
          endif ()
          set(QT_PATH ${CMAKE_PREFIX_PATH})
          message(${sp} "DEBUG_SUFFIX " ${DEBUG_SUFFIX})
          if (EXISTS "${QT_PATH}/bin")
              file(MAKE_DIRECTORY "${GLOBAL_ROOT}/libOutput/test/plugins/platforms")
              file(MAKE_DIRECTORY "${GLOBAL_ROOT}/libOutput/plugins/platforms")
              file(COPY "${QT_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll" DESTINATION "${GLOBAL_ROOT}/libOutput/plugins/platforms")
              file(COPY "${QT_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll" DESTINATION "${GLOBAL_ROOT}/libOutput/test/plugins/platforms")
              file(COPY "${QT_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.pdb" DESTINATION "${GLOBAL_ROOT}/libOutput/plugins/platforms")
              file(COPY "${QT_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.pdb" DESTINATION "${GLOBAL_ROOT}/libOutput/test/plugins/platforms")
              foreach (QT_LIB ${REQUIRED_LIBS})
                  set(filePath ${QT_PATH}/bin/Qt${QT_VERSION}${QT_LIB}${DEBUG_SUFFIX}.dll)
                  get_filename_component(barename ${filePath} NAME)
                  if (NOT EXISTS "${GLOBAL_ROOT}/libOutput/test/${barename}")
                      message(${sp} "Copying file : " ${QT_PATH}/bin/Qt${QT_VERSION}${QT_LIB}${DEBUG_SUFFIX}.dll to Tests)
                      file(COPY "${filePath}" DESTINATION "${GLOBAL_ROOT}/libOutput/test")
                  elseif (NOT EXISTS "${GLOBAL_ROOT}/libOutput/${barename}")
                      message(${sp} "Copying file : " ${QT_PATH}/bin/Qt${QT_VERSION}${QT_LIB}${DEBUG_SUFFIX}.dll to Root)
                      file(COPY "${filePath}" DESTINATION "${GLOBAL_ROOT}/libOutput/")
                  else ()
                      message(${sp} "Skipping copying of ${barename}")
                  endif ()
              endforeach (QT_LIB)
      
          else ()
              message(${sp} WARNING " COULD NOT FIND QT LIBS! ")
          endif ()
      endif ()
      
      1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #4

        My eyes are burning! especially the # Import QT dlls/etc part.
        There is no add_library/add_executable here so I have no clue what that CMakeLists is doing

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        D 1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #5

          Also you can't simply switch the compiler - you need the correct Qt for it. -Zc:__cplusplus is a msvc option.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          D 1 Reply Last reply
          1
          • VRoninV VRonin

            My eyes are burning! especially the # Import QT dlls/etc part.
            There is no add_library/add_executable here so I have no clue what that CMakeLists is doing

            D Offline
            D Offline
            Dariusz
            wrote on last edited by
            #6

            @VRonin Hahahha I know :d I'm in process of slowly... learning to update it.

            This part essentially copies all qt dlls I need into the exe location of my app

            The add_executable(${PROJECT_NAME} ${SRC}) is just that < There is nothing else that I do

            I forgot to add the link part to the code above which is >

            #### QT
            function(linkQTLibs)
                target_link_libraries(${PROJECT_NAME}
                        ${REQUIRED_LIBS_QUALIFIED}
                        )
            endfunction()
            

            But after that its zip.

            Esentially its

            Cmake:

            project(Hello world)
            set(CMAKE_CXX_STANDARD 20)
            
            include("pathToCmake/CmakeList.txt") # Which is the one posted in previous post 
            set(SRC main.cpp)
            add_executable(${PROJECT_NAME} ${SRC})
            linkQTLibs()
            

            And that's it.

            I don't set any more flags/etc. Its rather "simple" build.

            1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              Also you can't simply switch the compiler - you need the correct Qt for it. -Zc:__cplusplus is a msvc option.

              D Offline
              D Offline
              Dariusz
              wrote on last edited by
              #7

              @Christian-Ehrlicher In the cmake post above there is (clean up now) >

              set(QT_PATH "C:/Qt/6.1.2/")
              if (MSVC)
                  set(QT_PATH ${QT_PATH}msvc2019_64)
              else ()
                  set(QT_PATH ${QT_PATH}mingw81_64)
              endif ()
              

              This essentially " for now" set correct QT version for either MSVC or Mingw, In future I'll handle mac/arm/etc. But for now basics.

              So what I end up is, mingw as my toolchain and QT from mingw folder using either qt-mingw bundled compiler or program files/official one. Both fail.

              1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #8

                I can only tell you what I see - you somewhere mixing up MinGW and MSVC - you're using a MinGW compiler but your Qt thinks it's MSVC.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                D 1 Reply Last reply
                1
                • Christian EhrlicherC Christian Ehrlicher

                  I can only tell you what I see - you somewhere mixing up MinGW and MSVC - you're using a MinGW compiler but your Qt thinks it's MSVC.

                  D Offline
                  D Offline
                  Dariusz
                  wrote on last edited by
                  #9

                  @Christian-Ehrlicher Yeh, its... difficult. I think I don't know to "properly" set an explicit path to a specific qt version... what would be the cmake command for it ?

                  1 Reply Last reply
                  0
                  • VRoninV Offline
                    VRoninV Offline
                    VRonin
                    wrote on last edited by
                    #10

                    @Dariusz said in Unable to compile using Mingwx64 on windows, Command line option error:

                    what would be the cmake command for it ?

                    There shouldn't be one. Do not set it in CMakeLists.txt

                    The idea is that find_package should be able to find it. There are 2 ways to do this:

                    • have the Qt path in your PATH
                      • this is what you normally do on the command line, call qtenv2.bat from the Qt bin folder and it will set up your environment so that find_package will work
                    • add the Qt path to CMAKE_PREFIX_PATH
                      • this is what Qt Creator does automatically when you configure the Kit

                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                    ~Napoleon Bonaparte

                    On a crusade to banish setIndexWidget() from the holy land of Qt

                    D 1 Reply Last reply
                    2
                    • VRoninV VRonin

                      @Dariusz said in Unable to compile using Mingwx64 on windows, Command line option error:

                      what would be the cmake command for it ?

                      There shouldn't be one. Do not set it in CMakeLists.txt

                      The idea is that find_package should be able to find it. There are 2 ways to do this:

                      • have the Qt path in your PATH
                        • this is what you normally do on the command line, call qtenv2.bat from the Qt bin folder and it will set up your environment so that find_package will work
                      • add the Qt path to CMAKE_PREFIX_PATH
                        • this is what Qt Creator does automatically when you configure the Kit
                      D Offline
                      D Offline
                      Dariusz
                      wrote on last edited by
                      #11

                      @VRonin said in Unable to compile using Mingwx64 on windows, Command line option error:

                      @Dariusz said in Unable to compile using Mingwx64 on windows, Command line option error:

                      what would be the cmake command for it ?

                      There shouldn't be one. Do not set it in CMakeLists.txt

                      The idea is that find_package should be able to find it. There are 2 ways to do this:

                      • have the Qt path in your PATH
                        • this is what you normally do on the command line, call qtenv2.bat from the Qt bin folder and it will set up your environment so that find_package will work
                      • add the Qt path to CMAKE_PREFIX_PATH
                        • this is what Qt Creator does automatically when you configure the Kit

                      I dont want path/environemnt based Qt library. I have many projects each of which require specific qt to be run on/tested on. The idea of having to edit path every time I change projects is quite... bad. So I need to set qt via code & copy dlls manually as far as I can tell.

                      The idea that there will be only 1 qt version on the system is quite... frustrating to me.

                      VRoninV 1 Reply Last reply
                      0
                      • D Dariusz

                        @VRonin said in Unable to compile using Mingwx64 on windows, Command line option error:

                        @Dariusz said in Unable to compile using Mingwx64 on windows, Command line option error:

                        what would be the cmake command for it ?

                        There shouldn't be one. Do not set it in CMakeLists.txt

                        The idea is that find_package should be able to find it. There are 2 ways to do this:

                        • have the Qt path in your PATH
                          • this is what you normally do on the command line, call qtenv2.bat from the Qt bin folder and it will set up your environment so that find_package will work
                        • add the Qt path to CMAKE_PREFIX_PATH
                          • this is what Qt Creator does automatically when you configure the Kit

                        I dont want path/environemnt based Qt library. I have many projects each of which require specific qt to be run on/tested on. The idea of having to edit path every time I change projects is quite... bad. So I need to set qt via code & copy dlls manually as far as I can tell.

                        The idea that there will be only 1 qt version on the system is quite... frustrating to me.

                        VRoninV Offline
                        VRoninV Offline
                        VRonin
                        wrote on last edited by VRonin
                        #12

                        @Dariusz said in Unable to compile using Mingwx64 on windows, Command line option error:

                        The idea that there will be only 1 qt version on the system is quite... frustrating to me.

                        There isn't. I have 4 versions on my machine (5.5, 5.15, 6.1, dev). I don't know CLion but I'm sure there is a way to set CMAKE_PREFIX_PATH before it runs CMake, see https://stackoverflow.com/questions/54444846/equivalent-of-cmake-prefix-path-in-clion
                        Set it to C:/Qt/6.1.2/mingw81_64 and remove the set(QT_PATH

                        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                        ~Napoleon Bonaparte

                        On a crusade to banish setIndexWidget() from the holy land of Qt

                        1 Reply Last reply
                        0

                        • Login

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