Menu

#69 Static MinGW build fails

v1.0_(example)
open
nobody
None
5
2018-04-06
2018-04-04
No

I built QuaZIP with MinGW64 on a Linux host system. The CMAKE build used these options:
-DCMAKE_BUILD_TYPE=Release \ -DCMAKE_BINARY_DIR=bin \ -DBUILD_WITH_QT4:BOOL=OFF \ -DCMAKE_CXX_FLAGS="$CFLAGS -fPIC"

The result of my build are files:
include/…
lib/libquazip5.dll
lib/libquazip_static.a
lib/libquazip5.dll.a

I would like to note in passing that CMAKE_BINARY_DIR seems to be ignored and I have to move the .dll file to bin/ myself.
I also believe that 'libquazip_static.a' should be called 'libquazip5.a' or at least 'libquazip5_static.a'. I renamed the file (so please don't be confused by the output below).

Now I would like to use my build/installation to build another project with static linkage.

This is my own project's qmake file:

win32 {
    CONFIG += static
}

QT += gui widgets
LIBS += -lquazip5
win32:LIBS += /usr/x86_64-w64-mingw32/lib/libquazip5.a
win32:DEFINES += QUAZIP_STATIC

The linux build (dynamic) works as expected. The MinGW static build fails at the linker stage:

x86_64-w64-mingw32-g++ -g -static -static-libstdc++ -static-libgcc -Wl,-subsystem,windows -mthreads -o release/belki.exe object_script.belki.Release -lquazip5 /usr/x86_64-w64-mingw32/lib/libquazip5.a -lmingw32 -lqt5main -L/usr/x86_64-w64-mingw32/lib -L/usr/x86_64-w64-mingw32/lib/qt/plugins/styles /usr/x86_64-w64-mingw32/lib/qt/plugins/styles/libqwindowsvistastyle.a -L/usr/x86_64-w64-mingw32/lib/qt/plugins/platforms /usr/x86_64-w64-mingw32/lib/qt/plugins/platforms/libqwindows.a -lQt5EventDispatcherSupport -lQt5FontDatabaseSupport -lQt5ThemeSupport -lQt5AccessibilitySupport -lwinspool -lrpcrt4 -L/usr/x86_64-w64-mingw32/lib/qt/plugins/imageformats /usr/x86_64-w64-mingw32/lib/qt/plugins/imageformats/libqgif.a /usr/x86_64-w64-mingw32/lib/qt/plugins/imageformats/libqico.a /usr/x86_64-w64-mingw32/lib/qt/plugins/imageformats/libqjpeg.a -lQt5Widgets /usr/x86_64-w64-mingw32/lib/libQt5Widgets.a -lQt5Gui -ldwmapi -luxtheme /usr/x86_64-w64-mingw32/lib/libQt5Gui.a -lglu32 -lQt5Core -lopengl32 -lgdi32 -lcomdlg32 -loleaut32 -limm32 -ljpeg -lpng -lharfbuzz -lglib-2.0 -lshlwapi -lpcre -lintl -lgraphite2 -lfreetype -lbz2 /usr/x86_64-w64-mingw32/lib/libQt5Core.a -lmpr -lz -lpcre2-16 -liconv -lversion -lnetapi32 -luserenv -lole32 -luuid -lwinmm -lws2_32 -ladvapi32 -lshell32 -luser32 -lkernel32

with hundreds of messages like this:

/usr/x86_64-w64-mingw32/lib/libquazip5.a(quazip.cpp.obj):(.text+0x39): undefined reference to `__imp__ZNK14QMessageLogger7warningEPKcz'
/usr/x86_64-w64-mingw32/lib/libquazip5.a(quazip.cpp.obj):(.text+0x83): undefined reference to `__imp__ZN10QArrayData10deallocateEPS_yy'
/usr/x86_64-w64-mingw32/lib/libquazip5.a(quazip.cpp.obj):(.text+0xea): undefined reference to `__imp__ZN9QListData7disposeEPNS_4DataE'
/usr/x86_64-w64-mingw32/lib/libquazip5.a(quazip.cpp.obj):(.text+0x125): undefined reference to `__imp__ZN10QArrayData10deallocateEPS_yy'
/usr/x86_64-w64-mingw32/lib/libquazip5.a(quazip.cpp.obj):(.text+0x12c): undefined reference to `__imp__ZN9QDateTimeD1Ev'
/usr/x86_64-w64-mingw32/lib/libquazip5.a(quazip.cpp.obj):(.text+0x1b8): undefined reference to `__imp__ZN10QArrayData10deallocateEPS_yy'
/usr/x86_64-w64-mingw32/lib/libquazip5.a(quazip.cpp.obj):(.text+0x214): undefined reference to `__imp__ZN9QListData7disposeEPNS_4DataE'
/usr/x86_64-w64-mingw32/lib/libquazip5.a(quazip.cpp.obj):(.text+0x285): undefined reference to `__imp__ZN10QArrayData10deallocateEPS_yy'
/usr/x86_64-w64-mingw32/lib/libquazip5.a(quazip.cpp.obj):(.text+0x28c): undefined reference to `__imp__ZN9QDateTimeD1Ev'
…
/usr/x86_64-w64-mingw32/lib/libquazip5.a(qioapi.cpp.obj):(.text+0x233): undefined reference to `__imp__ZN9QIODevice5writeEPKcx'
/usr/x86_64-w64-mingw32/lib/libquazip5.a(qioapi.cpp.obj):(.text+0x307): undefined reference to `__imp__ZNK14QMessageLogger7warningEPKcz'
/usr/x86_64-w64-mingw32/lib/libquazip5.a(qioapi.cpp.obj):(.text+0x3e9): undefined reference to `__imp__ZNK14QMessageLogger7warningEPKcz'
/usr/x86_64-w64-mingw32/lib/libquazip5.a(qioapi.cpp.obj):(.text+0x413): undefined reference to `__imp__ZN9QSaveFile16staticMetaObjectE'
/usr/x86_64-w64-mingw32/lib/libquazip5.a(qioapi.cpp.obj):(.text+0x419): undefined reference to `__imp__ZNK11QMetaObject4castEP7QObject'
/usr/x86_64-w64-mingw32/lib/libquazip5.a(qioapi.cpp.obj):(.text+0x427): undefined reference to `__imp__ZN9QSaveFile6commitEv'

What's wrong with the static linkage to Qt?

Discussion

  • Sergey A. Tachenov

    I don't support CMake as I don't use it myself, so if you wish you can send me a patch to fix that CMAKE_BINARY_DIR and output naming issues (although I think the static suffix was meant to distinguish between the static version and the counterpart to DLL, used for dynamic linking).

    As for the main issue, looks like it attempts to do dynamic linking, just like if QUAZIP_STATIC wasn't defined. Surely it is in your project file, but just to double-check, could you post your compile output? I think the problem is earlier than the linking stage, it just shows up late, as usual.

     
  • Sergey A. Tachenov

    Oh, and by the way, QuaZIP is being migrated to GitHub, so a PR would be even better than a patch, if you intend to send any.