c++ - 如何使用mingw-w64通过链接时优化来构建Qt?

标签 c++ qt mingw-w64

使用g++ 8.1.0使用mingw-w64构建Qt 5.12.3效果很好。但是,一旦我将选项-ltcg添加到configure参数中,我就会得到构建错误。

configure调用如下所示:

../qt5/configure -prefix ../qt5Install -release -recheck-all -ltcg -confirm-license -opensource -platform win32-g++ -opengl desktop -nomake examples -nomake tests -system-freetype -I /c/Libraries/OpenCascade/3rdPartyMingw64/freetype-2.6.3-mingw-64/include -L/c/Libraries/OpenCascade/3rdPartyMingw64/freetype-2.6.3-mingw-64/bin -skip qtconnectivity -skip qtdeclarative -skip qtlocation -skip qtmultimedia -skip qtquickcontrols -skip qtquickcontrols2 -skip qtsensors -skip qtwebsockets -skip qtwinextras -skip qtwebchannel -skip qtwebengine

有没有人设法使用mingw-w64通过链接时间优化来构建Qt?诀窍是什么?

这里的构建错误是:
g++ -Wl,-s -shared -fno-keep-inline-dllexport -O3 -std=c++1z -fno-exceptions -flto -Wl,-subsystem,windows -Wl,--out-implib,C:/Libraries/qt/qt5Build/qtbase/lib/libQt5Gui.a -o ../../lib/Qt5Gui.dll @object_script.Qt5Gui.Release  -LC:/Libraries/OpenCascade/3rdPartyMingw64/freetype-2.6.3-mingw-64/bin -LC:/Libraries/qt/qt5Build/qtbase/lib C:/Libraries/qt/qt5Build/qtbase/lib/libQt5Core.a .obj/release/Qt5Gui_resource_res.o C:/Libraries/qt/qt5Build/qtbase/lib/libqtlibpng.a -LC:/Libraries/OpenCascade/3rdPartyMingw64/freetype-2.6.3-mingw-64/bin C:/Libraries/qt/qt5Build/qtbase/lib/libqtharfbuzz.a C:/mingw-w64-8.1/mingw64/x86_64-w64-mingw32/lib/libz.a -lgdi32 -lcomdlg32 -loleaut32 -limm32 -lwinmm -lws2_32 -lole32 -luuid -luser32 -ladvapi32 C:/mingw-w64-8.1/mingw64/x86_64-w64-mingw32/lib/libglu32.a C:/mingw-w64-8.1/mingw64/x86_64-w64-mingw32/lib/libopengl32.a C:/mingw-w64-8.1/mingw64/x86_64-w64-mingw32/lib/libgdi32.a C:/mingw-w64-8.1/mingw64/x86_64-w64-mingw32/lib/libuser32.a
.obj/release/qimage_compat.o (symbol from plugin):(.gnu.linkonce.t._ZTS12QPaintDevice+0x0): multiple definition of `typeinfo name for QPaintDevice'
.obj/release/qimage_ssse3.o:qimage_ssse3.cpp:(.rdata$_ZTS12QPaintDevice[_ZTS12QPaintDevice]+0x0): first defined here
.obj/release/qimage_compat.o (symbol from plugin):(.gnu.linkonce.t._ZTI12QPaintDevice+0x0): multiple definition of `typeinfo for QPaintDevice'
.obj/release/qimage_ssse3.o:qimage_ssse3.cpp:(.rdata$_ZTI12QPaintDevice[_ZTI12QPaintDevice]+0x0): first defined here
.obj/release/qimage_compat.o (symbol from plugin):(.gnu.linkonce.t._ZTS6QImage+0x0): multiple definition of `typeinfo name for QImage'
.obj/release/qimage_ssse3.o:qimage_ssse3.cpp:(.rdata$_ZTS6QImage[_ZTS6QImage]+0x0): first defined here

...
.obj/release/qimage.o (symbol from plugin):(.gnu.linkonce.t._ZTI18QRasterPaintEngine+0x0): multiple definition of `typeinfo for QRasterPaintEngine'
.obj/release/qdrawhelper_sse4.o:qdrawhelper_sse4.cpp:(.rdata$_ZTI18QRasterPaintEngine[_ZTI18QRasterPaintEngine]+0x0): first defined here
C:/Libraries/qt/qt5/qtbase/src/3rdparty/harfbuzz-ng/src/hb-shaper-list.hh:43:1: warning: '_hb_ot_shaper_shape_plan_data_create' violates the C++ One Definition Rule  [-Wodr]
 HB_SHAPER_IMPLEMENT (ot) /* <--- This is our main OpenType shaper. */
 ^
C:/Libraries/qt/qt5/qtbase/src/3rdparty/harfbuzz-ng/src/hb-ot-shape.cc:171:1: note: return value type mismatch
 _hb_ot_shaper_shape_plan_data_create (hb_shape_plan_t    *shape_plan,
 ^
C:/Libraries/qt/qt5/qtbase/src/3rdparty/harfbuzz-ng/src/hb-ot-shape-private.hh:37:8: note: type name 'hb_ot_shape_plan_t' should match type name 'hb_ot_shaper_shape_plan_data_t'
 struct hb_ot_shape_plan_t
        ^
C:/Libraries/qt/qt5/qtbase/src/3rdparty/harfbuzz-ng/src/hb-shaper-list.hh:43:1: note: the incompatible type is defined here
 HB_SHAPER_IMPLEMENT (ot) /* <--- This is our main OpenType shaper. */
 ^
C:/Libraries/qt/qt5/qtbase/src/3rdparty/harfbuzz-ng/src/hb-ot-shape.cc:171:1: note: '_hb_ot_shaper_shape_plan_data_create' was previously declared here
 _hb_ot_shaper_shape_plan_data_create (hb_shape_plan_t    *shape_plan,
 ^
C:/Libraries/qt/qt5/qtbase/src/3rdparty/harfbuzz-ng/src/hb-shaper-list.hh:43:1: warning: '_hb_ot_shaper_shape_plan_data_destroy' violates the C++ One Definition Rule  [-Wodr]
 HB_SHAPER_IMPLEMENT (ot) /* <--- This is our main OpenType shaper. */
 ^
C:/Libraries/qt/qt5/qtbase/src/3rdparty/harfbuzz-ng/src/hb-ot-shape.cc:200:1: note: type mismatch in parameter 1
 _hb_ot_shaper_shape_plan_data_destroy (hb_ot_shaper_shape_plan_data_t *plan)
 ^
C:/Libraries/qt/qt5/qtbase/src/3rdparty/harfbuzz-ng/src/hb-ot-shape-private.hh:37:8: note: type name 'hb_ot_shape_plan_t' should match type name 'hb_ot_shaper_shape_plan_data_t'
 struct hb_ot_shape_plan_t
        ^
C:/Libraries/qt/qt5/qtbase/src/3rdparty/harfbuzz-ng/src/hb-shaper-list.hh:43:1: note: the incompatible type is defined here
 HB_SHAPER_IMPLEMENT (ot) /* <--- This is our main OpenType shaper. */
 ^
C:/Libraries/qt/qt5/qtbase/src/3rdparty/harfbuzz-ng/src/hb-ot-shape.cc:200:1: note: '_hb_ot_shaper_shape_plan_data_destroy' was previously declared here
 _hb_ot_shaper_shape_plan_data_destroy (hb_ot_shaper_shape_plan_data_t *plan)
 ^
C:/Libraries/qt/qt5/qtbase/src/3rdparty/harfbuzz-ng/src/hb-shaper-list.hh:43:1: warning: '_hb_ot_shaper_face_data_destroy' violates the C++ One Definition Rule  [-Wodr]
 HB_SHAPER_IMPLEMENT (ot) /* <--- This is our main OpenType shaper. */
 ^
C:/Libraries/qt/qt5/qtbase/src/3rdparty/harfbuzz-ng/src/hb-ot-shape.cc:140:1: note: type mismatch in parameter 1
 _hb_ot_shaper_face_data_destroy (hb_ot_shaper_face_data_t *data)
 ^
C:/Libraries/qt/qt5/qtbase/src/3rdparty/harfbuzz-ng/src/hb-ot-layout-private.hh:154:8: note: type name 'hb_ot_layout_t' should match type name 'hb_ot_shaper_face_data_t'
 struct hb_ot_layout_t
        ^
C:/Libraries/qt/qt5/qtbase/src/3rdparty/harfbuzz-ng/src/hb-shaper-list.hh:43:1: note: the incompatible type is defined here
 HB_SHAPER_IMPLEMENT (ot) /* <--- This is our main OpenType shaper. */
 ^
C:/Libraries/qt/qt5/qtbase/src/3rdparty/harfbuzz-ng/src/hb-ot-shape.cc:140:1: note: '_hb_ot_shaper_face_data_destroy' was previously declared here
 _hb_ot_shaper_face_data_destroy (hb_ot_shaper_face_data_t *data)
 ^
collect2.exe: error: ld returned 1 exit status
mingw32-make[4]: *** [Makefile.Release:1219: ../../lib/Qt5Gui.dll] Error 1

最佳答案

似乎我已经找到一种通过链接时间优化构建Qt的方法:通过将链接器标志行设置为来修改文件mkspecs/win32-g++/qmake.confQMAKE_LFLAGS_LTCG = $$QMAKE_CFLAGS_LTCG -Wl,-allow-multiple-definition
使mingw-w64成功完成Qt构建。我将针对此链接时优化问题注册Qt错误报告。

链接时优化可将平均Qt DLL大小减少9%。我看到的唯一缺点是库Qt5OpenGL.dllQt5Xml.dll分别增长了0.3%和3.0%。

关于c++ - 如何使用mingw-w64通过链接时优化来构建Qt?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56131928/

相关文章:

c++ - 如何优化我的 Langford 序列函数?

c++ - 访问命名空间内的类中的枚举

c++ - opencv的Qt dll错误

c++ - 如何强制 QGraphicsView/QGraphicsScene 缩小到最小尺寸

qt - PyQt 将多页打印为 PDF 仅获取最后一页

Git Bash (mintty) 在 Windows 10 操作系统上速度极慢

c++ - 转换成本

c++ - 哪一个是更好的做法?

c++ - MinGW-Clang 的 libgcc_s_dw2-1.dll 丢失了吗?

c++ - 我正在尝试用 C++ 创建一个日志记录框架,但信息没有传递给记录器的子组件,我做错了什么?