创建构建目录
创建build工作目录,然后将qt源码复制到该目录下。之所以不直接在源码文件夹直接进行编译,因为编译过程会生成很多的中间文件,若直接在源码目录编译,生成的中间文件会生成到源码目录中的各个目录中,很难完全删除这些中间文件,如果需要重新编译,则需要重新解压源码文件到一个干净的目录,而这个解压过程是很耗时的。现在的做法,只需要删除qt-build目录下除源码目录外的所有文件即可获得纯净的编译环境。
另外还需要注意源码所在路径不能太长,否则编译时会提示找不到moc文件。
mkdir qt-build cd qt-build
MSVC
这里使用的是Visual Studio 2022。
调试版本使用qt动态库和msvc的c\c++动态库(/MDd),这样编译速度会很快,方便调试。
发布版本使用qt静态库和msvc的c\c++静态库(/MT),这样生成的程序不依赖Qt和C\C++ Runtime的DLL。
Qt6
配置选项
debug-and-release
..\configure -prefix "C:\lib\qt\6.9.1\debug-and-release" -confirm-license -opensource -debug-and-release -static -static-runtime -platform win32-msvc -no-opengl -nomake examples -nomake tests -skip qtwebengine -- -DCMAKE_CXX_STANDARD=20 -DCMAKE_CXX_STANDARD_REQUIRED=ON
debug
qt-everywhere-src-6.6.2\configure -prefix "C:\lib\qt\6.6.2\debug" -confirm-license -opensource -debug -shared -platform win32-msvc -c++std c++20 -qt-zlib -qt-pcre -skip qt5compat,qtactiveqt,qtcoap,qtconnectivity,qtdatavis3d,qtdoc,qtgrpc,qtlocation,qtlottie,qtmqtt,qtnetworkauth,qtopcua,qtpositioning,qtquickeffectmaker,qtremoteobjects,qtscxml,qtsensors,qtserialbus,qtserialport,qtspeech,qttools,qttranslations,qtvirtualkeyboard,qtwayland,qtwebchannel,qtwebengine,qtwebview -nomake examples -nomake tests -qt-libpng -qt-libjpeg -no-zstd -no-openssl -qt-freetype -qt-harfbuzz
release
qt-everywhere-src-6.6.2\configure -prefix "C:\lib\qt\6.6.2\release" -confirm-license -opensource -release -static -static-runtime -platform win32-msvc -c++std c++20 -qt-zlib -qt-pcre -skip qt5compat,qtactiveqt,qtcoap,qtconnectivity,qtdatavis3d,qtdoc,qtgrpc,qtlocation,qtlottie,qtmqtt,qtnetworkauth,qtopcua,qtpositioning,qtquickeffectmaker,qtremoteobjects,qtscxml,qtsensors,qtserialbus,qtserialport,qtspeech,qttools,qttranslations,qtvirtualkeyboard,qtwayland,qtwebchannel,qtwebengine,qtwebview -nomake examples -nomake tests -qt-libpng -qt-libjpeg -no-zstd -no-openssl -qt-freetype -qt-harfbuzz
编译
直接使用ninja.exe编译就可以,参数-j6中的6为线程数。
ninja.exe -j6
使用下面的命令也可以,本质上一样。
cmake --build . --parallel [编译线程数]
安装
ninja.exe install
或
cmake --install .
Qt5
配置选项
debug
qt-everywhere-src-5.15.13\configure -prefix "C:\lib\qt\5.15.13\debug" -confirm-license -opensource -debug -shared -platform win32-msvc -c++std c++2a -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -no-zstd -no-openssl -no-freetype -no-harfbuzz -nomake examples -nomake tests -skip qtactiveqt -skip qtandroidextras -skip qtcharts -skip qtconnectivity -skip qtdatavis3d -skip qtdeclarative -skip qtdoc -skip qtgamepad -skip qtgraphicaleffects -skip qtimageformats -skip qtlocation -skip qtlottie -skip qtmacextras -skip qtmultimedia -skip qtnetworkauth -skip qtpurchasing -skip qtremoteobjects -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 qtwebglplugin -skip qtwebview -skip qtwinextras -skip qtx11extras -skip qtxmlpatterns
release
qt-everywhere-src-5.15.13\configure -prefix "C:\lib\qt\5.15.13\release" -confirm-license -opensource -release -static -static-runtime -platform win32-msvc -c++std c++2a -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -no-zstd -no-openssl -no-freetype -no-harfbuzz -nomake examples -nomake tests -skip qtactiveqt -skip qtandroidextras -skip qtcharts -skip qtconnectivity -skip qtdatavis3d -skip qtdeclarative -skip qtdoc -skip qtgamepad -skip qtgraphicaleffects -skip qtimageformats -skip qtlocation -skip qtlottie -skip qtmacextras -skip qtmultimedia -skip qtnetworkauth -skip qtpurchasing -skip qtremoteobjects -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 qtwebglplugin -skip qtwebview -skip qtwinextras -skip qtx11extras -skip qtxmlpatterns
编译
nmake
或
jom.exe -j<线程数>
安装
nmake install
或
jom.exe install
MinGW-w64
这里使用的是msys2(ucrt64),并在msys2的命令行里执行。因为gcc编译速度比较慢,并且静态调试版本体积非常大,一个exe动辄大几百MB,所以我不使用MinGW的调试版本,只编译发布版本。
配置选项
qt-everywhere-src-6.6.2/configure -prefix "x:\qt\6.6.2\release" -confirm-license -opensource -release -static -static-runtime -platform win32-g++ -c++std c++20 -qt-zlib -qt-pcre -skip qt5compat,qtactiveqt,qtcoap,qtconnectivity,qtdatavis3d,qtdoc,qtgrpc,qtlocation,qtlottie,qtmqtt,qtnetworkauth,qtopcua,qtpositioning,qtquickeffectmaker,qtremoteobjects,qtscxml,qtsensors,qtserialbus,qtserialport,qtspeech,qttools,qttranslations,qtvirtualkeyboard,qtwayland,qtwebchannel,qtwebengine,qtwebview -nomake examples -nomake tests -qt-libpng -qt-libjpeg -no-zstd -no-openssl -qt-freetype -qt-harfbuzz qt-everywhere-src-6.2.7/configure -prefix "x:\qt\6.2.7\release" -confirm-license -opensource -release -static -static-runtime -platform win32-g++ -c++std c++20 -qt-zlib -qt-pcre -nomake examples -nomake tests -no-zstd
编译和安装
cmake --build . --parallel [编译线程数] cmake --install .
发表回复