Unable to compile using Mingwx64 on windows, Command line option error
-
Hey
It seems to me like Qt configuration for mingw is somehow broken and it adds command lines to cmake & cause mingw to go bananas.
Some other peron has the same error here > https://stackoverflow.com/questions/67824944/unrecognized-command-line-option-zc-cplusplus-and-unrecognized-command-line
I'm on Clion & Mingwxt64 qt 6.1.2
Problems were encountered while collecting compiler information: c++.exe: error: unrecognized command line option '-Zc:__cplusplus' c++.exe: error: unrecognized command line option '-permissive-'; did you mean '-fpermissive'?
Can any1 hint out on how can I fix this?
-
@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 ()
-
Also you can't simply switch the compiler - you need the correct Qt for it.
-Zc:__cplusplus
is a msvc option. -
@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 doI 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.
-
@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.
-
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.
-
@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 ?
-
@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 thatfind_package
will work
- this is what you normally do on the command line, call
- add the Qt path to
CMAKE_PREFIX_PATH
- this is what Qt Creator does automatically when you configure the Kit
- have the Qt path in your PATH
-
@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 thatfind_package
will work
- this is what you normally do on the command line, call
- 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.
- have the Qt path in your PATH
-
@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 toC:/Qt/6.1.2/mingw81_64
and remove theset(QT_PATH