簡體   English   中英

如何使用 MinGW 編譯器和 SSL 支持靜態編譯 Qt

[英]how to statically compile Qt using MinGW compiler and SSL support

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.

所以這是一個古老的問題,有很多關於這個主題的問題,但很少有解決方案可以解決這個問題。 其中一些問題(和問題):

還有很多

和我自己的一些問題(使用 OpenSSL v1.1.1d & Qt 5.13 和 MinGW ):

這些問題中的大多數沒有答案,並且提供的那些答案(顯然)對編譯沒有幫助,原因是一些錯誤 output 或只是 OpenSSL 從未鏈接(內置於便攜式/二進制應用程序中)或許多其他錯誤。

此外,關於使用-ssl-openssl-linked-openssl以及它們各自的含義似乎存在很多混淆。 此外,如果應該使用-L/path/to/libs/static -l library1 -l library2 vs 使用OPENSSL_HOME變量並指定標題和 static / 鏈接庫等的路徑

請注意:

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 以這兩個帖子的形式提供了一些幫助:

這個問題的目的是給出一個詳細的解釋和逐步的方法,讓那些需要編譯 static Qt 版本的人得到一些支持和指導。

這是一個不自然的“問題”,但是在每個特定問題中看到這么多問題沒有/很少有針對精選案例的解決方案,因此很難獲得通用解決方案。

我發布這個問題是希望提供一個可以使所有人受益的通用解決方案。

我最近才注意到這個問題,所以我還沒有時間從頭開始編寫完整的分步說明,但是我能夠在我的環境中構建 qt-5.15.0 的 static基於 MSYS2 shell 以及 MinGW-w64 和 GCC 10 個來自http://winlibs.com的個人構建已經在相同的環境中編譯。

openssl 的版本是 1.1.1g,這樣構建的(靜態庫和共享庫):

# 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 的 static 構建的步驟:

# 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

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.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM