Qt 6 undefined reference to WinMain on MinGW
-
@Christian-Ehrlicher ABSOLUTE LEGEND!
-
@Christian-Ehrlicher said in Qt 6 undefined reference to WinMain on MinGW:
-target_link_libraries(MyLib PRIVATE Qt6::Core Qt6::Gui Qt6::Widgets)
+target_link_libraries(MyLib PUBLIC Qt6::Core Qt6::Gui Qt6::Widgets)This fixes the build for some reason
-
@VRonin said in Qt 6 undefined reference to WinMain on MinGW:
This fixes the build for some reason
Linking all Qt libraries private for a shared lib somehow confuses cmake so
INTERFACE_LINK_LIBRARIES
is not interpreted when linking against this lib and the Qt libraries later on.btw: PRIVATE is not correct, it should be PUBLIC and therefore it was not noticed until now.
-
@Christian-Ehrlicher said in Qt 6 undefined reference to WinMain on MinGW:
PRIVATE is not correct, it should be PUBLIC
In this particular case it is indeed wrong but if you think of a library not exposing Qt (for example, a library to read/write xml files that internally uses
QXmlStreamReader
/QXmlStreamWriterer
), the application linking to it might or might not link to Qt itself soPUBLIC
in that case would be wrong.
If this is unclear I can change the minimal example to show what I mean -
@VRonin It's not unclear. Just a reason why noone noticed until now :)
-
-
Dear all,
i write here for fellow googlers.
I stumbled to this thread with setup of msys2 - toolchain + qt6 binaries "mingw81_64". The project compiled fine under QT5 (and it compiles fine with qt6 on linux / ubuntu 20.04) - but with qt6.1.0 it failed on windows.
I did have a library, but it was not qt6 depending, like
add_library( foo_common STATIC ) add_library( foo_engine STATIC ) target_link_libraries( foo_engine PRIVATE foo_common ) ... add_executable( ${NAME} ... ) target_link_libraries( ${NAME} PUBLIC Qt6::Widgets ) target_link_libraries( ${NAME} PRIVATE foo_common foo_engine )
I did try few swap places but it had no effect. Finally i added suggested
target_link_libraries( ${NAME} PUBLIC Qt6::EntryPoint)
after the existing target_link_libraries calls and it did work.
-
@supa5000 said in Qt 6 undefined reference to WinMain on MinGW:
I did try few swap places
Try replacing
target_link_libraries( ${NAME} PUBLIC Qt6::Widgets ) target_link_libraries( ${NAME} PRIVATE foo_common foo_engine )
with
target_link_libraries( ${NAME} PRIVATE foo_common foo_engine Qt6::Widgets)
while it is a workaround it worked for me
-
@VRonin said in Qt 6 undefined reference to WinMain on MinGW:
while it is a workaround it worked for me
Thanks for the detail - i tried but the result remained for some reason the same. I did - to be sure - try fresh (rm -rf build && cd build && cmake ../ && make) build but no effect.
To give the full details the actual link line was (that did not work until the entrypoint explicitly linked below)
target_link_libraries( ${name} PRIVATE foo_common foo_engine Qt6::Widgets Qt6::Qml Qt6::Quick) # Try2: target_link_libraries( ${name} PRIVATE foo_common foo_engine Qt6::Qml Qt6::Quick Qt6::Widgets) # enabling this makes the link go ok. # target_link_libraries( ${name PUBLIC Qt6::EntryPoint)
i tried also (as comment try2) move the Widgets as the last item but it seemed not have effect.
-
I just pulled 6.2.0 and i stumbled again this; this time the Qt6::Entrypoint target was not found during CMake - so i removed it -- and now i am back with the missing WinMain issue.
Any ideas or updates? The linked bug https://bugreports.qt.io/browse/QTBUG-93671 seems stalled..
-
I'm running into this in windows. I've been looking at the qmake -d 2>&1 of a Qt example vs a QWT example. At some point in the QWT qmake generation it seems to loose the entrypoint_private module.
qt example: DEBUG 1: C:/tools/Qt/6.4.2/msvc2019_64/mkspecs/features/qt_functions.prf:379: modules := core gui entrypoint_private
qwt example: DEBUG 1: C:/tools/Qt/6.4.2/msvc2019_64/mkspecs/features/qt_functions.prf:379: modules := core gui printsupport concurrent opengl openglwidgets svgI haven't been able to figure out the clean fix yet. I ended up diffing the makefiles between the examples and one the major differences was that the QWT example was missing the lib: Qt6EntryPoint.lib
So I added it to the qwt example pro like:
LIBS += C:\Qt\6.4.2\msvc2019_64\lib\Qt6EntryPoint.liband then the release version at least built successfully.
note: for diffing the qmake -d output it's handy to do a cut like this (powershell):
qmake -d 2>&1 | % { $_ -split ':' | select -last 1 }this strips out a lot of paths making the diff easier to scan.
This was using Qwt 6.2.0, git sha:92baef.