本文介绍了如何使用MinGW编译器和SSL支持静态编译Qt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Windows(使用MinGW编译器)上静态编译带有OpenSSL支持的Qt 此Qt构建的理想结果"是构建并交付具有内置SSL支持的可移植Qt应用程序.

How to statically compile Qt with OpenSSL support on Windows (with MinGW compiler)The desired 'outcome' of this Qt build is to build and ship a portable Qt application with built-in SSL support.

因此,这是一个古老的问题,与此主题相关的问题很多,但解决该问题的解决方案很少.其中的一些问题(和问题):

So this is an age old problem with a multitude of questions on this topic, yet very few solutions exist that solves the problem. Some of these questions (and problems):

  • QT https SSL support for static QT static program build - getting 'Protocol "https" is unknown'
  • about compiling openssl inside qt application
  • Build Qt static from source enabling OpenSSL support
  • Compile static version of QT + OpenSSL Support
  • how to compile qt static with open ssl
  • Compiling static for Windows with OpenSSL

还有更多

和我自己的一些问题(将OpenSSL v1.1.1d& Qt 5.13与MinGW结合使用):

and some of my own questions (using OpenSSL v1.1.1d & Qt 5.13 with MinGW ):

这些问题大多数都没有答案,并且(显然)提供的那些答案由于某些错误输出或只是从未将OpenSSL链接(内置到可移植/二进制应用程序中)或许多其他错误而无助于编译.

Most of these questions do not have answers, and those answers provided (obviously) did not help in compiling, due to some error output or simply OpenSSL was never linked (built into the portable/binary application), or many other errors.

此外,关于使用 -ssl -openssl-linked -openssl 以及它们各自的含义,似乎存在很多困惑.另外,如果应该使用 -L/path/to/libs/static -l library1 -l library2 与使用 OPENSSL_HOME env变量并指定标头&的路径.静态/链接库等

Further, there appears to be alot of confusion about using -ssl, -openssl-linked, -openssl and what each means. Also, if one should use -L/path/to/libs/static -l library1 -l library2 vs using the OPENSSL_HOME env variable and specify the path to headers & static / linked libraries, etc

请注意:

理想情况下,在编译时,将需要特定的库指令,例如 OpenSSL v1.0.2 OpenSSL v1.1 qmake 除了在构建过程中应考虑的事项以外,还使用那些特定的库构建静态Qt的参数.

Ideally, in compiling, specific instructions for libraries would be required such as OpenSSL v1.0.2 or OpenSSL v1.1 and the qmake arguments in building a static Qt with those specific libraries in addition to things that should be considered during the build process.

Qt说什么?

Qt通过这2个帖子的形式提供了一些帮助:

Qt has provide some help in the form of these 2 posts:

  • 使用MinGW 和Powershell脚本为Windows构建静态Qt,该脚本确实使用MinGW静态编译了Qt,但是将OpenSSL库 -l 和/或 -L 的各种组合(和置换)添加到各种路径(.lib ),( .a ),头文件等根本不起作用
  • 使用MinGW编译OpenSSL
  • Building a static Qt for Windows using MinGW with a Powershell script which does compile Qt statically using MinGW, but adding the various combinations (and permutations) of OpenSSL libraries -l and/or -L to the various paths (.lib), (.a), header files, etc simply did not work
  • Compiling OpenSSL with MinGW

该问题的目的是给出详细的解释和逐步方法,以允许需要使用SSL编译静态Qt版本的人员提供一些支持和指导.

这是一个不自然的问题",但是在每个特定问题中看到如此多的问题而没有/很少有针对樱桃挑剔案例的解决方案,这使得很难获得通用的解决方案.

This is an unnatural "question", but having seen so many questions with no/very few solutions for cherrypicked cases in each specific question makes a general solution very difficult to obtain.

我正在发布此问题,以期希望有一个可以使所有人受益的通用解决方案.

推荐答案

我最近才注意到这个问题,所以我还没有时间从头开始编写完整的分步说明.能够在我的环境中基于MSYS2 shell与MinGW-w64进行静态构建的qt-5.15.0,以及来自 http://winlibs.com/,并且所有先决条件都已在同一环境中编译.

I just noticed this question just recently, so I haven't had time yet to write complete step-by-step instructions from the ground up, but I was able to do a static build of qt-5.15.0 in my environment which is based on MSYS2 shell together with MinGW-w64 with GCC 10 personal build from http://winlibs.com/ with all the prerequisites already compiled in the same environment.

openssl的版本为1.1.1g,如下所示(静态和共享库):

The version of openssl was 1.1.1g built like this (static and shared libraries):

# location of Perl
PERLDIR=/d/Prog/Perl/strawberry-perl-5.30.0.1-64bit-portable/perl
# install destination
INSTALLPREFIX=/d/Prog/winlibs64-10.1.0/custombuilt
# for 32-bit replace mingw64 with mingw in the next line
./Configure --prefix=$INSTALLPREFIX threads shared zlib-dynamic -DOPENSSL_NO_CAPIENG mingw64 &&
make &&
PATH=$PERLDIR/bin:$PATH make -j1 install OPENSSLDIR_dir=$INSTALLPREFIX &&
strip $INSTALLPREFIX/bin/*.exe $INSTALLPREFIX/bin/*.dll &&
cp -f $INSTALLPREFIX/lib/libcrypto.a $INSTALLPREFIX/lib/libeay32.a && 
cp -f $INSTALLPREFIX/lib/libcrypto.dll.a $INSTALLPREFIX/lib/libeay32.dll.a && 
cp -f $INSTALLPREFIX/lib/libssl.a $INSTALLPREFIX/lib/libssleay32.a && 
cp -f $INSTALLPREFIX/lib/libssl.dll.a $INSTALLPREFIX/lib/libssleay32.dll.a && 
cp -f ms/applink.c $INSTALLPREFIX/include/openssl/ && 
echo Success

以下是我做静态构建qt-5.15.0的步骤:

Here are the steps I did to do the static build of qt-5.15.0:

# location of Python
PY2DIR=/d/Prog/Python/WinPython-64bit-2.7.13.1Zero/python-2.7.13.amd64
# location of all the prerequisites
MINGWPREFIX=/d/Prog/winlibs64-10.1.0/custombuilt
# install destination
INSTALLPREFIX=/d/Prog/winlibs64-10.1.0/custombuilt
# fix missing SHARE_INFO_1 in qtbase/src/corelib/io/qfilesystemengine_win.cpp 
echo "#include <levmar.h>" | gcc -E -xc - &> /dev/null && sed -i.bak -e "s/\(#\s*include <\)lm\.h\(>\)/\1levmar.h\2\n\1lmshare.h\2\n\1lmapibuf.h\2/" qtbase/src/corelib/io/qfilesystemengine_win.cpp
# avoid using missing debug ICU libraries in static builds
sed -i.bak -e "s/\(lsicu..\)d/\1/g" qtbase/src/corelib/configure.json
# configure
mkdir -p build_static &&
cd build_static &&
PATH=$PATH:$PY2DIR ../configure -platform win32-g++ -prefix $INSTALLPREFIX/qt -opensource -confirm-license -release -static -no-pch -no-rpath -strip -skip "qtserialbus" -qpa windows -gif -sql-odbc -sql-sqlite -opengl desktop -icu -system-pcre -dbus -system-sqlite -system-zlib -system-libpng -system-libjpeg -system-doubleconversion -system-freetype -system-harfbuzz -libproxy -system-proxies -openssl -openssl-linked -no-xcb -no-compile-examples -skip qtwebengine -nomake examples -system-proxies -plugin-manifests -pkg-config -I $MINGWPREFIX/include/freetype2 -I $MINGWPREFIX/include/mariadb &&
sed -i.bak -e "s/\(-lclang\)\.a/\1 -lpthread/" qttools/src/qdoc/Makefile.* &&
cd .. &&
# build
(
 PATH=$PATH:$PY2DIR mingw32-make -Cbuild_static release QMAKE_CXXFLAGS="-fcommon" QMAKE_LFLAGS="-Wl,-allow-multiple-definition" || (
  make -Cbuild_static/qttools/src/qdoc &&
  PATH=$PATH:$PY2DIR mingw32-make -Cbuild_static release QMAKE_CXXFLAGS="-fcommon" QMAKE_LFLAGS="-Wl,-allow-multiple-definition"
)) &&
# workaround for missing qmake.exe
cp build_static/qtbase/bin/qmake.exe build_static/qtbase/qmake/ &&
make -Cbuild_static install &&
# manually create qt.conf
echo "[Paths]" > $INSTALLPREFIX/qt/bin/qt.conf &&
echo "Prefix=../../qt" >> $INSTALLPREFIX/qt/bin/qt.conf &&
echo Success

我通过构建KeePassXC( https://github.com/keepassxreboot/keepassxc/archive/2.5.4.tar.gz )对它进行调试,结果软件包完全没有Qt DLL,并且运行良好.

I have tested the result by building KeePassXC (https://github.com/keepassxreboot/keepassxc/archive/2.5.4.tar.gz) against it and the resulting package had no Qt DLLs at all and it ran fine.

这篇关于如何使用MinGW编译器和SSL支持静态编译Qt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 05:18