posts - 49, comments - 32, trackbacks - 0, articles - 0

Qt5.10.1 static compiling on Windows MSVC/Ubuntu g++

Posted on 2019-03-08 11:00 宋鹏 阅读(57) 评论(0)  编辑 收藏 引用 所属分类: Qt

环境:Windows10 / vs2013 or vs2015(Qt5.10.1是以C++11为基础,因此vs2008歇菜了)

参考代码里的Readme:

1.安装:
安装了perl/python2.7/ruby 
安装了vs2015

2.环境变量
add C:\Perl\bin to PERL_HOME
add %PERL_HOME% to path
add C:\Python27 to PYTHON_HOME
add %PYTHON_HOME% to path
add C:\Ruby26\bin to RUBY_HOME
add %RUBY_HOME% to path
add C:\Qt\Qt5.10.1\5.10.1\msvc2015\bin to QT_LIB_HOME
add %QT_LIB_HOME% to path
add C:\Qt\Qt5.10.1\Tools\QtCreator\bin to QT_CREATOR_HOME
add %QT_CREATOR_HOME% to path
注意:像官方推荐的一样,这里最好用同一版本的binary安装的Qt比较安装。
注意:如果这里没有添加QT的路径,就会被推荐用nmake编译,否则被推荐用jom编译。
3.代码:
代码解压缩到C:\Qt\Qt5.10.1_src
于是Configure文件在:
C:\Qt\Qt5.10.1_src

qtbase文件夹在:
C:\Qt\Qt5.10.1_src\qtbase

4.修改配置从MD到MT(动态链接改为静态链接):
修改文件:
C:\Qt\Qt5.10.1_src\qtbase\mkspecs\common\msvc-desktop.conf
修改下面几行代码:
QMAKE_CFLAGS_RELEASE    = $$QMAKE_CFLAGS_OPTIMIZE -MD
QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += $$QMAKE_CFLAGS_OPTIMIZE -Zi -MD
QMAKE_CFLAGS_DEBUG      = -Zi -MDd
改为:
QMAKE_CFLAGS_RELEASE    = $$QMAKE_CFLAGS_OPTIMIZE -MT
QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += $$QMAKE_CFLAGS_OPTIMIZE -Zi -MT
QMAKE_CFLAGS_DEBUG      = -Zi -MTd

修改文件:
C:\Qt\Qt5.10.1_src\qtbase\mkspecs\common\msvc-version.conf
在最前面加上:
QMAKE_MSC_VER = 1900
否则会报错:
msvc-version.conf loaded but qmake_msc_ver isn't set

运行C:\Qt\Qt5.10.1_src>configure.bat 确认配置
5.编译:
<license>选择-opensource
控制台选择:
开始 -> Visual Studio 2015 -> Developer Command Prompt for VS2015 

疯狂的缩减编译选择,可以用来尝试最小化编译,当然我失败了( comercial user 可以用qt的Congiguration tool 然而我并没有,有些以来无法zh)
configure -confirm-license -opensource -platform win32-msvc -static -debug-and-release -prefix "C:\Qt\Qt5.10.1_static"  -make libs -nomake tools -nomake examples -nomake tests -skip qt3d -skip qtandroidextras -skip qtcanvas3d -skip qtcharts -skip qtconnectivity -skip qtdatavis3d -skip qtdeclarative -skip qtdoc -skip qtgamepad -skip qtgraphicaleffects -skip qtimageformats -skip qtlocation -skip qtmacextras -skip qtmultimedia -skip qtnetworkauth -skip qtpurchasing -skip qtquickcontrols -skip qtquickcontrols2 -skip qtscript -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtspeech -skip qtsvg -skip qttools -skip qttranslations -skip qtvirtualkeyboard -skip qtwayland -skip qtwebchannel -skip qtwebengine -skip qtwebsockets -skip qtwebview -skip qtwinextras -skip qtx11extras -skip qtxmlpatterns -no-feature-texthtmlparser -no-feature-textodfwriter -no-feature-concurrent -no-feature-effects -no-feature-sharedmemory -no-feature-systemsemaphore -no-feature-im -no-feature-process -no-feature-dom -no-feature-filesystemmodel -no-feature-filesystemwatcher -no-feature-graphicsview -no-feature-graphicseffect -no-feature-sizegrip -no-feature-calendarwidget -no-feature-printpreviewwidget -no-feature-keysequenceedit -no-feature-colordialog -no-feature-filedialog -no-feature-fontdialog -no-feature-printpreviewdialog -no-feature-progressdialog -no-feature-inputdialog -no-feature-errormessage -no-feature-wizard -no-feature-datawidgetmapper -no-feature-imageformat_bmp -no-feature-imageformat_ppm -no-feature-imageformat_xbm -no-feature-imageformat_png -no-feature-imageformat_jpeg -no-feature-image_heuristic_mask -no-feature-image_text -no-feature-colornames -no-feature-cups -no-feature-paint_debug -no-feature-freetype -no-feature-translation -no-feature-codecs -no-feature-big_codecs -no-feature-iconv -no-feature-ftp -no-feature-udpsocket -no-feature-networkproxy -no-feature-socks5 -no-feature-networkdiskcache -no-feature-bearermanagement -no-feature-completer -no-feature-fscompleter -no-feature-desktopservices -no-feature-mimetype -no-feature-systemtrayicon -no-feature-undocommand -no-feature-undostack -no-feature-undogroup -no-feature-undoview -no-feature-statemachine -no-feature-gestures -no-feature-dbus -no-opengl 

成功的组合1(想编译哪个 就去掉哪个skip):
configure -confirm-license -opensource -platform win32-msvc -static -debug-and-release -prefix "C:\Qt\Qt5.10.1_mt_static" -make libs -nomake tools -nomake examples -nomake tests -skip qt3d -skip qtandroidextras -skip qtcanvas3d -skip qtcharts -skip qtconnectivity -skip qtdatavis3d -skip qtdeclarative -skip qtdoc -skip qtgamepad -skip qtgraphicaleffects -skip qtimageformats -skip qtlocation -skip qtmacextras -skip qtmultimedia -skip qtnetworkauth -skip qtpurchasing -skip qtquickcontrols -skip qtquickcontrols2 -skip qtscript -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtspeech -skip qtsvg -skip qttools -skip qttranslations -skip qtvirtualkeyboard -skip qtwayland -skip qtwebchannel -skip qtwebengine -skip qtwebsockets -skip qtwebview -skip qtwinextras -skip qtx11extras -skip qtxmlpatterns -no-opengl 
尝试2:
configure -confirm-license -opensource -platform win32-msvc -static -debug-and-release -prefix "C:\Qt\Qt5.10.1_mt_static" -make libs -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -nomake tools -nomake examples -nomake tests -skip qtandroidextras -skip qtgamepad -skip qtmacextras -skip qttools -skip qtwinextras -skip qtx11extras  -no-openssl 
Note: No wayland-egl support detected. Cross-toolkit compatibility disabled.
结果:
Static builds of QtWebEngine aren't supported.
"Some of the required modules (android|ios|winrt|qtHaveModule(webengine)) are not available."
skip webengine 继续测试:
configure -confirm-license -opensource -platform win32-msvc -static -debug-and-release -prefix "C:\Qt\Qt5.10.1_mt_static" -make libs -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -nomake tools -nomake examples -nomake tests -skip qtandroidextras -skip qtgamepad -skip qtmacextras -skip qttools -skip qtwebengine -skip qtwinextras -skip qtx11extras  -no-openssl 
结果:
成功

成功的组合2:
configure -confirm-license -opensource -platform win32-msvc -static -debug-and-release -prefix "C:\Qt\Qt5.10.1_mt_static" -make libs -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -nomake tools -nomake examples -nomake tests -skip qtandroidextras -skip qtgamepad -skip qtmacextras -skip qttools -skip qtwebengine -skip qtwinextras -skip qtx11extras  -no-openssl 
成功的组合1只是在单独编译qtbase时有用,于是以后采用的成功的组合2,总结命令为:
cd C:\Qt\Qt5.10.1_src
configure -confirm-license -opensource -platform win32-msvc -static -debug-and-release -prefix "C:\Qt\Qt5.10.1_mt_static" -make libs -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -nomake tools -nomake examples -nomake tests -skip qtandroidextras -skip qtgamepad -skip qtmacextras -skip qttools -skip qtwebengine -skip qtwinextras -skip qtx11extras  -no-openssl 
jom -j2
jom install

plus1:
WARNING: Using OpenGL ES 2.0 on Windows without ANGLE.
The build will most likely fail.
Specify -opengl desktop to use regular OpenGL.

plus2:
-skip qtwebengine , 都是Linux only
Webengine options:
  -webengine-alsa ................ Enable ALSA support [auto] (Linux only)
  -webengine-pulseaudio .......... Enable PulseAudio support [auto]
                                   (Linux only)
  -webengine-embedded-build ...... Enable Linux embedded build [auto]
                                   (Linux only)
  -webengine-icu ................. Use system ICU libraries [system/qt]
                                   (Linux only)

plus3:
Static builds of QtWebEngine aren't supported.

环境:Ubuntu 18.10/linux g++


1.安装:

安装了perl/python/ruby ( Linux 中 python2.x 的名字是python python3.x的名字是python3 )
统一安装:

sudo apt-get install build-essential libpcap0.8-dev libx11-dev libfreetype6-dev libavahi-gobject-dev libsm-dev libxrender-dev perl python ruby


2.环境变量:
linux的环境变量 只要不是特殊安装的,应该都被包含在内了

3.代码:
同上

4.动态链接改为静态链接:
linux没有md/mt,编译都时候 直接-static应该就可以。

5.编译:
尝试的组合1:
./configure -confirm-license -opensource -static -debug-and-release -prefix "/home/peng/Share/Qt5.10.1_static" -make libs -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -qt-xcb -opengl desktop -nomake tools -nomake examples -nomake tests -skip qtandroidextras -skip qtgamepad -skip qtmacextras -skip qttools -skip qtwebengine -skip qtwinextras -no-openssl 
编译出错:
qfilesystemengine_unix.cpp:101:12: error: ‘int renameat2(int, const char*, int, const char*, unsigned int)’ was declared ‘extern’ and later ‘static’ [-fpermissive]
bug fix:
据说要安装glibc2.28来解决。。

参考文献:
https://retifrav.github.io/blog/2018/02/17/build-qt-statically/
https://blog.csdn.net/u012822903/article/details/62058287


只有注册用户登录后才能发表评论。
【推荐】超50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理