您尚未登录。

楼主 #1 2019-04-27 15:54:15

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,223
积分: 9197

windows 编译静态库版本 Qt

参考链接: http://amin-ahmadi.com/2017/11/01/how-to-build-qt-5-9-2-static-using-mingw/





缘由: 发行用户软件不需要带一堆动态链接库。





离线

楼主 #2 2019-04-27 19:23:47

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,223
积分: 9197

Re: windows 编译静态库版本 Qt





离线

楼主 #3 2019-04-27 19:26:12

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,223
积分: 9197

Re: windows 编译静态库版本 Qt

QQ20190427192508.png

下面我来试一试.


用的是git 安装的时候附带的 bash:

./configure -opensource -confirm-license -static -platform win32-g++ -prefix d:/Qt/Qt5.9.7/5.9.7/mingw530_32_static/ -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -no-compile-examples -nomake tools -nomake demos -nomake tests -nomake examples





离线

楼主 #4 2019-04-27 19:29:23

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,223
积分: 9197

Re: windows 编译静态库版本 Qt

debugdump@DESKTOP-32PC8B1 MINGW64 /d/Qt/Qt5.9.7/5.9.7/Src
$ ./configure -opensource -confirm-license -static -platform win32-g++ -prefix d:/Qt/Qt5.9.7/5.9.7/mingw530_32_static/ -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -no-compile-examples -nomake tools -nomake demos -nomake tests -nomake examples
+ cd qtbase
+ /d/Qt/Qt5.9.7/5.9.7/Src/qtbase/configure -top-level -opensource -confirm-license -static -platform win32-g++ -prefix d:/Qt/Qt5.9.7/5.9.7/mingw530_32_static/ -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -no-compile-examples -nomake tools -nomake demos -nomake tests -nomake examples
Creating qmake...
................................................  ....................................Done.
Info: creating super cache file D:\Qt\Qt5.9.7\5.9.7\Src\.qmake.super
ERROR: Invalid value 'demos' supplied to command line option 'nomake'.

提示了一个错误, 所以只能改一下命令行:

./configure -opensource -confirm-license -static -platform win32-g++ -prefix d:/Qt/Qt5.9.7/5.9.7/mingw530_32_static/ -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -no-compile-examples -nomake tools  -nomake tests -nomake examples





离线

楼主 #5 2019-04-27 19:32:04

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,223
积分: 9197

Re: windows 编译静态库版本 Qt

嗯, 这次 OK:

debugdump@DESKTOP-32PC8B1 MINGW64 /d/Qt/Qt5.9.7/5.9.7/Src
-examples -nomake tools  -nomake tests -nomake examplestype -opengl desktop -no-compile-
+ cd qtbase
+ /d/Qt/Qt5.9.7/5.9.7/Src/qtbase/configure -top-level -opensource -confirm-license -static -platform win32-g++ -prefix d:/Qt/Qt5.9.7/5.9.7/mingw530_32_static/ -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -no-compile-examples -nomake tools -nomake tests -nomake examples
Creating qmake...
.Done.
Info: creating stash file D:\Qt\Qt5.9.7\5.9.7\Src\.qmake.stash

This is the Qt Open Source Edition.

You have already accepted the terms of the Open Source license.

Running configuration tests...
Checking for valid makespec... yes
Checking for alloca() in alloca.h... no
Checking for alloca() in malloc.h... yes
Checking for target architecture... i386
Checking for SSE2 instructions... yes
Checking for SSE3 instructions... yes
Checking for SSSE3 instructions... yes
Checking for SSE4.1 instructions... yes
Checking for SSE4.2 instructions... yes
Checking for AVX instructions... yes
Checking for AVX2 instructions... yes
Checking for AVX512 F instructions... yes
Checking for AVX512 BW instructions... yes
Checking for AVX512 CD instructions... yes
Checking for AVX512 DQ instructions... yes
Checking for AVX512 ER instructions... yes
Checking for AVX512 IFMA instructions... yes
Checking for AVX512 PF instructions... yes
Checking for AVX512 VBMI instructions... yes
Checking for AVX512 VL instructions... yes
Checking for C++14 support... yes
Checking for C++1z support... yes
Checking for D-Bus >= 1.2... no
Checking for F16C instructions... yes
Checking for D-Bus >= 1.2 (host)... yes
Checking for IncrediBuild... no
Checking for udev... no
Checking for -Og support... yes
Checking for POSIX fallocate()... no
Checking for precompiled header support... yes
Checking for STL compatibility... yes
Checking for eventfd... no
Checking for inotify... no
Checking for slog2... no
Checking for 64 bit atomics... yes
Checking for DoubleConversion... no
Checking for O_CLOEXEC... no
Checking for working std::atomic for function pointers... yes
Checking for getaddrinfo()... yes
Checking for getifaddrs()... no
Checking for IPv6 ifname... no
Checking for OpenSSL Headers... no
Checking for XCB >= 1.5 (core)... no
Checking for Direct 2D... no
Checking for DirectWrite... yes
Checking for DirectWrite 2... no
Checking for Desktop OpenGL... yes
Checking for EGL... no
Checking for evdev... no
Checking for GBM... no
Checking for KMS... no
Checking for LinuxFB... no
Checking for mtdev... no
Checking for OpenVG... no
Checking for default QPA platform... windows
Checking for tslib... no
Checking for xkbcommon... no
Checking for XLib... no
Checking for uxtheme.h... yes
Checking for CUPS... no
Checking for DB2 (IBM)... no
Checking for InterBase... no
Checking for MySQL... no
Checking for OCI (Oracle)... no
Checking for ODBC... yes
Checking for PostgreSQL... no
Checking for SQLite (version 2)... no
Checking for TDS (Sybase)... no
Checking for Direct3D 12... no
Checking for SDL2... no
Checking for Assimp... no
Checking for Autodesk FBX... no
Checking for Wayland EGL library... no
Checking for BlueZ... no
Checking for sensorfw... no
Checking for Gypsy... no
Checking for WinRT Geolocation API... no
Checking for DirectShow... yes
Checking for evr.h... yes
Checking for GStreamer 1.0... no
Checking for GStreamer 0.10... no
Checking for OpenAL... no
Checking for libresourceqt5... no
Checking for Windows Audio Services... no
Checking for WMF... no
Checking for wmsdk.h... no
Checking for WShellItem... yes
Checking for embedded... no
Checking for Python 2...
Checking for system ninja... no
Done running configuration tests.

Configure summary:

Build type: win32-g++ (i386, CPU features: <none>)
Configuration: sse2 sse3 ssse3 sse4_1 sse4_2 avx avx2 avx512f avx512bw avx512cd avx512dq avx512er avx512ifma avx512pf avx512vbmi avx512vl f16c largefile optimize_debug precompile_header debug_and_release release debug build_all c++11 c++14 c++1z concurrent dbus no-pkg-config release_tools static stl
Build options:
  Mode ................................... debug and release; default link: debug; optimized tools
  Optimize debug build ................... yes
  Optimize release build for size ........ no
  Building shared libraries .............. no
  Using C++ standard ..................... C++1z
  Using gold linker ...................... no
  Using precompiled headers .............. yes
  Using LTCG ............................. no
  Target compiler supports:
    SSE .................................. SSE2 SSE3 SSSE3 SSE4.1 SSE4.2
    AVX .................................. AVX AVX2 F16C
    AVX512 ............................... F ER CD PF DQ BW VL IFMA VBMI
  Build parts ............................ libs
  App store compliance ................... no
Qt modules and options:
  Qt Concurrent .......................... yes
  Qt D-Bus ............................... yes
  Qt D-Bus directly linked to libdbus .... no
  Qt Gui ................................. yes
  Qt Network ............................. yes
  Qt Sql ................................. yes
  Qt Testlib ............................. yes
  Qt Widgets ............................. yes
  Qt Xml ................................. yes
Support enabled for:
  Using pkg-config ....................... no
  QML debugging .......................... yes
  udev ................................... no
  Using system zlib ...................... no
Qt Core:
  DoubleConversion ....................... yes
    Using system DoubleConversion ........ no
  GLib ................................... no
  iconv .................................. no
  ICU .................................... no
  Logging backends:
    journald ............................. no
    syslog ............................... no
    slog2 ................................ no
  Using system PCRE2 ..................... no
Qt Network:
  getaddrinfo() .......................... yes
  getifaddrs() ........................... no
  IPv6 ifname ............................ no
  libproxy ............................... no
  OpenSSL ................................ no
    Qt directly linked to OpenSSL ........ no
  SCTP ................................... no
  Use system proxies ..................... yes
Qt Gui:
  Accessibility .......................... yes
  FreeType ............................... yes
    Using system FreeType ................ no
  HarfBuzz ............................... yes
    Using system HarfBuzz ................ no
  Fontconfig ............................. no
  Image formats:
    GIF .................................. yes
    ICO .................................. yes
    JPEG ................................. yes
      Using system libjpeg ............... no
    PNG .................................. yes
      Using system libpng ................ no
  EGL .................................... no
  OpenVG ................................. no
  OpenGL:
    ANGLE ................................ no
    Desktop OpenGL ....................... yes
    Dynamic OpenGL ....................... no
    OpenGL ES 2.0 ........................ no
    OpenGL ES 3.0 ........................ no
    OpenGL ES 3.1 ........................ no
  Session Management ..................... yes
Features used by QPA backends:
  evdev .................................. no
  libinput ............................... no
  INTEGRITY HID .......................... no
  mtdev .................................. no
  tslib .................................. no
  xkbcommon-evdev ........................ no
QPA backends:
  DirectFB ............................... no
  EGLFS .................................. no
  LinuxFB ................................ no
  VNC .................................... no
  Mir client ............................. no
  Windows:
    Direct 2D ............................ no
    DirectWrite .......................... yes
    DirectWrite 2 ........................ no
Qt Widgets:
  GTK+ ................................... no
  Styles ................................. Fusion Windows WindowsXP WindowsVista
Qt PrintSupport:
  CUPS ................................... no
Qt Sql:
  DB2 (IBM) .............................. no
  InterBase .............................. no
  MySql .................................. no
  OCI (Oracle) ........................... no
  ODBC ................................... yes
  PostgreSQL ............................. no
  SQLite2 ................................ no
  SQLite ................................. yes
    Using system provided SQLite ......... no
  TDS (Sybase) ........................... no
Qt SerialBus:
  Socket CAN ............................. no
  Socket CAN FD .......................... no
QtXmlPatterns:
  XML schema support ..................... yes
Qt QML:
  QML interpreter ........................ yes
  QML network support .................... yes
Qt Quick:
  Direct3D 12 ............................ no
  AnimatedImage item ..................... yes
  Canvas item ............................ yes
  Support for Qt Quick Designer .......... yes
  Flipable item .......................... yes
  GridView item .......................... yes
  ListView item .......................... yes
  Path support ........................... yes
  PathView item .......................... yes
  Positioner items ....................... yes
  ShaderEffect item ...................... yes
  Sprite item ............................ yes
Qt Gamepad:
  SDL2 ................................... no
Qt 3D:
  Assimp ................................. yes
  System Assimp .......................... no
  Output Qt3D Job traces ................. no
  Output Qt3D GL traces .................. no
Qt 3D GeometryLoaders:
  Autodesk FBX ........................... no
Qt Wayland Client ........................ no
Qt Wayland Compositor .................... no
Qt Bluetooth:
  BlueZ .................................. no
  BlueZ Low Energy ....................... no
  Linux Crypto API ....................... no
Qt Sensors:
  sensorfw ............................... no
Qt Quick Controls 2:
  Styles ................................. Default Material Universal
Qt Quick Templates 2:
  Hover support .......................... yes
  Multi-touch support .................... yes
Qt Positioning:
  Gypsy GPS Daemon ....................... no
  WinRT Geolocation API .................. no
Qt Location:
  Geoservice plugins:
    OpenStreetMap ........................ yes
    HERE ................................. yes
    Esri ................................. yes
    Mapbox ............................... yes
    MapboxGL ............................. yes
    Itemsoverlay ......................... yes
Qt Multimedia:
  ALSA ................................... no
  GStreamer 1.0 .......................... no
  GStreamer 0.10 ......................... no
  Video for Linux ........................ no
  OpenAL ................................. no
  PulseAudio ............................. no
  Resource Policy (libresourceqt5) ....... no
  Windows Audio Services ................. no
  DirectShow ............................. yes
  Windows Media Foundation ............... no
  Media player backend ................... DirectShow
Qt WebEngine:
  Embedded build ......................... no
  Pepper Plugins ......................... yes
  Printing and PDF ....................... yes
  Proprietary Codecs ..................... no
  Spellchecker ........................... yes
  WebRTC ................................. yes
  Using system ninja ..................... no

Note: Using static linking will disable the use of dynamically
loaded plugins. Make sure to import all needed static plugins,
or compile needed modules into the library.

Note: No wayland-egl support detected. Cross-toolkit compatibility disabled.

WARNING: Python version 2 (2.7.5 or later) is required to build QtWebEngine.

Qt is now configured for building. Just run 'make'.
Once everything is built, you must run 'make install'.
Qt will be installed into 'd:\Qt\Qt5.9.7\5.9.7\mingw530_32_static'.

Prior to reconfiguration, make sure you remove any leftovers from
the previous build.




离线

楼主 #6 2019-04-27 20:37:10

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,223
积分: 9197

Re: windows 编译静态库版本 Qt

接着

mingw32-make -j8
mingw32-make install

非常顺利, 把刚刚编译的Qt (D:\Qt\Qt5.9.7\5.9.7\mingw530_32_static\bin\qmake.exe) 添加到 qtcreator

编译demo 程序

不用带任何 dll, 可以直接跑:

QQ20190427203412.png

不过我还是不放心, 把 编译好的 exe 文件发到没有 Qt 的电脑再试一试.





离线

楼主 #7 2019-04-27 20:48:34

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,223
积分: 9197

Re: windows 编译静态库版本 Qt

实践证明还是要拷贝三个文件:

libgcc_s_dw2-1.dll
libstdc++-6.dll
libwinpthread-1.dll

才能运行





离线

楼主 #8 2019-04-27 21:20:05

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,223
积分: 9197

Re: windows 编译静态库版本 Qt

参考这个帖子: https://forum.qt.io/topic/62614/remove-dependency-to-libwinpthread-1-dll/12

完美解决上面的问题

pro 文件添加:

CONFIG+=static
QMAKE_LFLAGS+="-static -static-libgcc -static-libstdc++ -lstdc++"
DEFINES+=STATIC





离线

楼主 #9 2019-04-27 21:24:12

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,223
积分: 9197

Re: windows 编译静态库版本 Qt

QQ20190427212238.png

完美解决, 不依赖任何非 WIndows自带 dll 文件了.





离线

楼主 #10 2019-04-28 09:17:00

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,223
积分: 9197

Re: windows 编译静态库版本 Qt

2019-04-28_091418.png

2019-04-28_091216.png

把昨天制作的 静态 Qt SDK 解压到办公室电脑, 编译一个 GcodeSenderGUIthreads.pro, 一切正常。

选择了 Release 之后, 可执行文件不需要手动 strip 了.





离线

#11 2019-04-28 09:21:45

Jmhh247
会员
注册时间: 2018-12-21
已发帖子: 262
积分: 262

Re: windows 编译静态库版本 Qt

好帖,留名学习

离线

楼主 #12 2019-05-05 09:13:11

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,223
积分: 9197

Re: windows 编译静态库版本 Qt

后来发现一个恼人的问题, 虽然可以不用带任何第三方dll文件, 但是不能在 windows xp 32bit 电脑运行。
后来发现一个恼人的问题, 虽然可以不用带任何第三方dll文件, 但是不能在 windows xp 32bit 电脑运行。
后来发现一个恼人的问题, 虽然可以不用带任何第三方dll文件, 但是不能在 windows xp 32bit 电脑运行。
后来发现一个恼人的问题, 虽然可以不用带任何第三方dll文件, 但是不能在 windows xp 32bit 电脑运行。
后来发现一个恼人的问题, 虽然可以不用带任何第三方dll文件, 但是不能在 windows xp 32bit 电脑运行。





离线

楼主 #13 2019-05-05 09:14:09

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,223
积分: 9197

Re: windows 编译静态库版本 Qt

接下来还得试一试 Qt5.6 才行: https://blog.csdn.net/libaineu2004/article/details/80415755

仍然使用 mingw:

Qt5可以使用msvc编译器和mingw编译器,而msvc的编译器从2015开始就对xp的支持变差,就算通过各种编译配置命令设置,能xp下运行,但是会很可能发生一些奇奇怪怪的bug。而mingw编译器没有这个问题,同一个版本可以在xp win7 win10各个系统使用,而无需其他配置。另外,Qt5目前有两个长期支持版本(Long Term Support)Qt5.6和Qt5.9,Qt5.6可以在XP和win7及以上系统开发,而Qt5.9只支持win7以上的系统开发和部署。 所以如果想使用Qt5的新功能,又想开发出的软件能在xp系统上运行,可以选择Qt5.6的mingw-32bit版本或者vs2013版本进行开发。

1、Qt从5.7版本开始不再支持WinXP系统,即编译生成的exe文件无法在WinXP系统运行。

2、Qt5.6是长期支持版本Long Term Support,它可以支持WinXP-32bit的系统。参考:http://doc.qt.io/qt-5.6/supported-platforms.html

下载网站是:

http://download.qt.io/official_releases/qt/5.6/

请注意,这几个版本是完全ok的:

qt-opensource-windows-x86-msvc2013_64-5.6.3.exe

qt-opensource-windows-x86-msvc2013-5.6.3.exe

qt-opensource-windows-x86-mingw492-5.6.3.exe

 

vs2015编译出来的版本在WinXP是不ok的,在WinXP环境下,会出现字体乱码(含删除线,本人亲测)的问题。

qt-opensource-windows-x86-msvc2015_64-5.6.3.exe

qt-opensource-windows-x86-msvc2015-5.6.3.exe





离线

楼主 #14 2019-05-05 09:58:31

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,223
积分: 9197

Re: windows 编译静态库版本 Qt

QQ20190505095737.png


Qt 5.6.3 正在安装。





configure -opensource -confirm-license -static -platform win32-g++ -prefix d:/Qt/Qt5.6.3/5.6.3/mingw492_32_static/ -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -no-compile-examples -nomake tools  -nomake tests -nomake examples

QQ20190505105708.png
配置完成





2019-05-05_115759.png
编译完成


参考: https://www.affgt.com/index.php/149/





离线

楼主 #15 2019-05-05 15:07:51

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,223
积分: 9197

Re: windows 编译静态库版本 Qt

使用上面的 Qt 5.6.3 static SDK

再配合 8楼的工程配置

pro 文件添加:

CONFIG+=static
QMAKE_LFLAGS+="-static -static-libgcc -static-libstdc++ -lstdc++"
DEFINES+=STATIC

现在在 Windows XP 上安静地运行了。





离线

楼主 #16 2019-05-19 15:36:30

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,223
积分: 9197

Re: windows 编译静态库版本 Qt

QQ20190519153049.png

用上面的 static qt sdk 编译了一下 candle

发现缺模块, 看来还得想办法把 winextras 整合到里面才行.





离线

#17 2019-08-22 11:13:21

qter
会员
注册时间: 2017-09-14
已发帖子: 40
积分: 40

Re: windows 编译静态库版本 Qt

晕哥 说:

参考这个帖子: https://forum.qt.io/topic/62614/remove-dependency-to-libwinpthread-1-dll/12

完美解决上面的问题

pro 文件添加:

CONFIG+=static
QMAKE_LFLAGS+="-static -static-libgcc -static-libstdc++ -lstdc++"
DEFINES+=STATIC

感谢!终于搞定了,可以不用带其他 dll 直接跑了

离线

#18 2019-09-07 09:57:41

岁月留痕
会员
注册时间: 2019-09-06
已发帖子: 4
积分: 4

Re: windows 编译静态库版本 Qt

48d0bf7e8b13e33182413dbfa60283a6.png

试了一下静态链接, 非常OK

离线

#19 2020-01-02 14:59:33

异乡是故乡
会员
注册时间: 2019-11-15
已发帖子: 74
积分: 73.5

Re: windows 编译静态库版本 Qt

wow

厉害了, 非常感谢!

我说呢, 公司的软件总是带一堆7788动态链接库.

离线

#20 2020-01-06 09:25:29

srovio
会员
注册时间: 2019-10-16
已发帖子: 15
积分: 9.5

Re: windows 编译静态库版本 Qt

收藏备用!

离线

#21 2020-01-07 14:37:08

szchen2006
会员
注册时间: 2019-10-09
已发帖子: 216
积分: 166.5

Re: windows 编译静态库版本 Qt

学习了!

离线

#22 2020-01-21 18:21:24

XZHDJH
会员
注册时间: 2020-01-18
已发帖子: 37
积分: 37

Re: windows 编译静态库版本 Qt

收藏

离线

#23 2020-02-17 17:34:37

我心飞翔
会员
注册时间: 2019-12-25
已发帖子: 82
积分: 82

Re: windows 编译静态库版本 Qt

晕哥 说:

参考这个帖子: https://forum.qt.io/topic/62614/remove-dependency-to-libwinpthread-1-dll/12

完美解决上面的问题

pro 文件添加:

参考这个帖子搞定! 现在不依赖其他第三方dll了,谢谢!

离线

#24 2021-07-11 19:35:54

海石生风
会员
所在地: 深圳
注册时间: 2019-07-02
已发帖子: 513
积分: 634
个人网站

Re: windows 编译静态库版本 Qt

静态链接QT的话,如果不买授权就必须将源码开源,所以用处不大吧。

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn