With Qt/MSBuild generated static lib is only 1MB... why?
-
I am trying to migrate an old Qt VS project to the new Qt/MSBuild workflow. It uses a static build of Qt 5.15 I built myself. The old project has series of custom build tasks calling moc, uic and rcc, and it links to the Qt 5.7 libs in the include and preprocessor definitions. This makes it difficult to link agaisnt a newer version of Qt since the lib names change all the time. Thankfully Qt VS Tools allows migrating an old Qt project to the more modern Qt/MSBuild approach. You list the Qt modules you need under Qt Project Settings. In this case I only need core;gui;uitools;widgets;winextras, and then qmake takes care of linking the right libs to MSBuild. However, no matter what I do, it is only generating a 1MB .lib file. This obviously makes compilation of the target DLL fail in the linking steps, as it cannot find any of the Qt functions. But in the old project it actually generated a 100MB lib and compilation succeeds.
I made sure to include QT_STATICPLUGIN in the preprocessor definitions, but it doesn't seem to make any difference. Am I missing something here? Do I need to change something in my main project? Here you can see the changes I made.Out of curiosity I also tried making a new blank QtWidgets project. The debug exe with my static Qt 5.15 build is about 30MB in size, same if I change the target to a DLL. But if I change the target to Static library (.lib), the size is only 480kb. So I'm not sure if this is actually a Qt/MSbuild issue. Any help with this would be very appreciated. I've been bashing my head against this for hours.
-
Hi and welcome to devnet,
Did you build Qt statically ?
-
Yes. My older Qt 5.7 static build works fine with the custom build steps, generating a 100MB .lib file. I am trying to migrate the project to use Qt 5.15. With Qt/MSBuild, it generates that 1MB .lib file always, with both 5.7 and 5.15 static builds.
For building Qt 5.15 I used the following configuration
..\configure -no-freetype -qt-libpng -qt-zlib -qt-pcre -qt-libjpeg -c++std c++11 -mp -debug-and-release -opensource -confirm-license -static -static-runtime -make libs -nomake tools -nomake examples -nomake tests -prefix C:\Qt\qt-5_15-x86-msvc2017-static -platform win32-msvc2017 -opengl desktop -no-openssl -style-windowsvista -optimize-size
-
Then are you sure that your static build is actually used ?
-
@SGaist Yes. I pointed Qt VS Tools to my static build, as well the Qt Project Settings. In fact I don't have any non-static builds on my computer.
-
Still no solution for this... This might actually be a bug from qmake in Qt/MSBuild workflow when trying to generate a static lib. Because changing the target to EXE or DLL generates a proper static binary in the Qt/MSBuild workflow. In this case I need this to produce a single static .lib since the GUI component is not the final target. The old workflow works as intended. How can I report this issue to the Qt developers. Is there a public bug tracker?
-
It seems to only generate the full lib if I add the following manually under "additional dependencies" under Project properties > Librarian
qtpcre2.lib;qtmain.lib;qwindows.lib;qico.lib;Qt5Core.lib;Qt5Gui.lib;Qt5Widgets.lib;UxTheme.lib;qwindowsvistastyle.lib;Qt5WindowsUiAutomationSupport.lib;Qt5FontDatabaseSupport.lib;Qt5EventDispatcherSupport.lib;Qt5FontDatabaseSupport.lib;Qt5ThemeSupport.lib;qtharfbuzz.lib;Ws2_32.lib;Netapi32.lib;Userenv.lib;Ws2_32.lib;Wtsapi32.lib;Imm32.lib;WinMM.lib;Version.lib;Netapi32.lib;Dwmapi.lib;%(AdditionalDependencies)
Why though? Shouldn't qmake automatically determine the necessary libraries according to the Qt Project Settings modules under "Qt Modules"? "core;gui;uitools;widgets;winextras" is what I have there. I was looking forward of getting rid of the hardcoded lib names, so upgrading the project to a newer Qt version would be seamless, otherwise this newfangled "Qt/MSBuild" system offers no advantage over legacy Qt Project configuration.
-
Without the ugly workaround of using "additional dependencies" here's the full commandline options for the migrated VS project. I really don't see what could be the problem.
/permissive- /MP /ifcOutput "C:\Git\GLideN64\projects\msvc\build\Win32\Release\GLideNUI" /GS /analyze- /W3 /Zc:wchar_t /I"." /I"release" /I".\GeneratedFiles" /I"C:\Git\GLideN64\projects\msvc....\src\osal" /I"C:\Qt\qt-5_15-x86-msvc2019-static\include" /I"C:\Git\GLideN64\projects\msvc" /I"C:\Users\Kim\AppData\Local\Temp\bnz5mksk.no3" /I"C:\Qt\qt-5_15-x86-msvc2019-static\include\QtUiTools" /I"C:\Qt\qt-5_15-x86-msvc2019-static\include\QtWidgets" /I"C:\Qt\qt-5_15-x86-msvc2019-static\include\QtWinExtras" /I"C:\Qt\qt-5_15-x86-msvc2019-static\include\QtGui" /I"C:\Qt\qt-5_15-x86-msvc2019-static\include\QtCore" /I"C:\Qt\qt-5_15-x86-msvc2019-static\mkspecs\win32-msvc" /I"C:\Git\GLideN64\projects\msvc\build\Win32\Release\GLideNUI\moc" /I"C:\Git\GLideN64\projects\msvc\build\Win32\Release\GLideNUI\uic" /Gm- /O2 /Fd"C:\Git\GLideN64\projects\msvc\build\Win32\Release\GLideNUI\vc16.0.pdb" /Zc:inline /fp:precise /D "QT_NO_DEBUG" /D "NDEBUG" /D "OS_WINDOWS" /D "_WINDOWS" /D "UNICODE" /D "WIN32" /D "QT_STATICPLUGIN" /D "_UNICODE" /D "_ENABLE_EXTENDED_ALIGNED_STORAGE" /D "QT_UITOOLS_LIB" /D "QT_WIDGETS_LIB" /D "QT_WINEXTRAS_LIB" /D "QT_GUI_LIB" /D "QT_CORE_LIB" /errorReport:prompt /WX- /Zc:forScope /GR /Gd /Oy- /MT /std:c++17 /FC /Fa"C:\Git\GLideN64\projects\msvc\build\Win32\Release\GLideNUI" /EHsc /nologo /Fo"C:\Git\GLideN64\projects\msvc\build\Win32\Release\GLideNUI" /Fp"C:\Git\GLideN64\projects\msvc\build\Win32\Release\GLideNUI\GLideNUI.pch" /diagnostics:column /OUT:"C:\Git\GLideN64\projects\msvc\bin\Win32\Release\lib\GLideNUI.lib" /LTCG "imm32.lib" "Ws2_32.lib" /MACHINE:X86 /NOLOGO /LIBPATH:"C:\Qt\qt-5_15-x86-msvc2019-static\lib"