Statisk forbindelse til Qt på Windows ved hjælp af CMake

Indlæg af Hanne Mølgaard Plasc

Problem



Jeg arbejder på et Qt-projekt, der er udviklet på Linux, men har også en statisk forbundet Windows-bygning. Jeg kan bygge den på Linux og Windows ved hjælp af den samme CMakeLists.txt-fil. Den strimler ned til:


project(muckturnier)
set(CMAKE\_CXX\_STANDARD 11)
set(CMAKE\_CXX\_REQUIRED TRUE)
find\_package(Qt5 COMPONENTS Widgets Sql)
include\_directories(${Qt5Widgets\_INCLUDES} ${Qt5Sql\_INCLUDES})
set(CMAKE\_AUTOMOC ON)
set(muckturnier\_SRCS ${CMAKE\_CURRENT\_SOURCE\_DIR}/SomeCode.cpp)
add\_executable(muckturnier ${muckturnier\_SRCS})
target\_link\_libraries(muckturnier ${Qt5Widgets\_LIBRARIES} ${Qt5Sql\_LIBRARIES})


Men jeg klarte ikke at lave en statisk koblet opbygning på Windows via CMake endnu. Når jeg manuelt indstiller de respektive inklusiv dirs, bygger det hele fint, men jeg får en linkerfejl til sidst:


[100\%] Linking CXX executable muckturnier.exe
C:/Qt/5.6\_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x228d):
undefined reference to `hb\_buffer\_create'
C:/Qt/5.6\_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x22a4):
undefined reference to `hb\_buffer\_set\_unicode\_funcs'
C:/Qt/5.6\_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x22b7):
undefined reference to `hb\_buffer\_pre\_allocate'
C:/Qt/5.6\_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x22bf):
undefined reference to `hb\_buffer\_allocation\_successful'
C:/Qt/5.6\_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x23ef):
undefined reference to `hb\_buffer\_clear\_contents'
C:/Qt/5.6\_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x241f):
undefined reference to `hb\_buffer\_add\_utf16'
C:/Qt/5.6\_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x2432):
undefined reference to `hb\_buffer\_set\_segment\_properties'
C:/Qt/5.6\_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x243a):
undefined reference to `hb\_buffer\_guess\_segment\_properties'
C:/Qt/5.6\_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x2455):
undefined reference to `hb\_buffer\_set\_flags'
C:/Qt/5.6\_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x2555):
undefined reference to `hb\_shape\_full'
C:/Qt/5.6\_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x2578):
undefined reference to `hb\_buffer\_get\_length'
C:/Qt/5.6\_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x258c):
undefined reference to `hb\_buffer\_destroy'
C:/Qt/5.6\_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x264a):
undefined reference to `hb\_buffer\_get\_glyph\_infos'
C:/Qt/5.6\_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x2662):
undefined reference to `hb\_buffer\_get\_glyph\_positions'
C:/Qt/5.6\_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x28f8):
undefined reference to `hb\_buffer\_reverse'
C:/Qt/5.6\_static/lib/libQt5Gui.a(qtextengine.o):qtextengine.cpp:(.text+0x2941):
undefined reference to `hb\_buffer\_destroy'
C:/Qt/Tools/mingw492\_32/bin/../lib/gcc/i686-w64-mingw32/4.9.2/../../../../i686-w
64-mingw32/bin/ld.exe: C:/Qt/5.6\_static/lib/libQt5Gui.a(qtextengine.o): bad relo
c address 0x7a in section `.text$\_ZN7QVectorIN11QTextLayout11FormatRangeEEaSERKS
2\_[\_\_ZN7QVectorIN11QTextLayout11FormatRangeEEaSERKS2\_]'
collect2.exe: error: ld returned 1 exit status
CMakeFilesmuckturnier.diruild.make:424: recipe for target 'muckturnier.exe' f
ailed
mingw32-make[2]: *** [muckturnier.exe] Error 1
CMakeFilesMakefile2:141: recipe for target 'CMakeFiles/muckturnier.dir/all' fai
led
mingw32-make[1]: *** [CMakeFiles/muckturnier.dir/all] Error 2
makefile:82: recipe for target 'all' failed
mingw32-make: *** [all] Error 2


Derfor oprettede jeg en qmake .pro-fil til at lave den statiske opbygning. Denne strimler ned til:


QMAKE\_CXXFLAGS += -std=c++11
CONFIG += qt
CONFIG += static
QT += widgets
QT += sql
HEADERS += SomeCode.h
SOURCES += SomeCode.cpp
TARGET = muckturnier


Ved hjælp af qmake (fra den statiske Qt) kan jeg lave den statiske konstruktion uden problemer. Så min statiske Qt build er bare fint, og det er et CMake problem.


Hvad er der galt her? Tak for al hjælp!

Bedste reference


Jeg tror du er offer for denne fejl (stadig uløst). Jeg er ikke 100\% sikker på, hvad der går galt, men du kan finde nogle ideer i kommentarerne. [4]