msvc编译qt源码(qt6之前版本)

配置环境

根据源码里的readme(D:\Qt\Qt5.9.9\5.9.9\Src\readme)安装对应的依赖环境,如果是整个源码编译必须都安装

msvc编译qt源码(qt6之前版本)_第1张图片

 Qt for Windows - Requirements | Qt 5.15

Qt for Windows - Building from Source | Qt 5.15

Qt WebEngine Platform Notes | Qt WebEngine 5.15.14

编译指令

尝试了很多组

configure -prefix E:/qtbuild  -debug-and-release -opensource  -force-debug-info -opengl dynamic -platform win32-msvc -c++std c++11 -skip qtmultimedia -skip qtsensors -skip qtwebengine -skip qtgamepad -nomake examples -nomake tests -mp -skip qtlocation -skip qtserialbus -confirm-license

configure -prefix E:/qtbuild -confirm-license -shared -opensource -force-debug-info -platform win32-msvc  -release -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  -mp

./configure -prefix E:\qtbuild -opensource -confirm-license -debug-and-release  -force-debug-info   -shared  -platform win32-msvc    -optimized-qmake   -c++std c++11   --rpath=no   -pch   -skip qt3d   -skip qtactiveqt   -skip qtandroidextras   -skip qtcanvas3d   -skip qtconnectivity   -skip qtdatavis3d   -skip qtdoc   -skip qtgamepad   -skip qtlocation   -skip qtmacextras   -skip qtnetworkauth   -skip qtpurchasing   -skip qtremoteobjects   -skip qtscript   -skip qtscxml   -skip qtsensors   -skip qtspeech   -skip qtsvg   -skip qttools   -skip qttranslations   -skip qtwayland   -skip qtwebengine   -skip qtwebview   -skip qtwinextras   -skip qtx11extras   -skip qtxmlpatterns   -make libs   -nomake examples   -nomake tools -nomake tests   -gui   -widgets   -dbus-runtime   --glib=no   --iconv=no   --pcre=qt   --zlib=qt   -no-openssl   --freetype=qt   --harfbuzz=qt   -no-opengl    --xcb=no     --libpng=qt   --libjpeg=qt   --sqlite=qt   -plugin-sql-sqlite -mp 

 Qt5.10.1 static compiling on Windows MSVC/Ubuntu g++ - - C++博客

configure参数说明:

-prefix 生成目标库的目录

-release 生成release版本  -debug 生成debug版本  -debug-and-release生成debug和release版本

-opensource 编译开源版  -commercial 编译商业版 (参数可选)

-static 生成静态库lib文件  -shared 生成动态库dll文件 (参数可选,默认是shared)/*** 注:静态库与动态库区别是在生成目标文件的链接方式上,静态库采用静态链接,在生成的目标文件(如.exe文件)中会包含库文件代码,而动态库在程序编译时并不会被连接到目标代码中,而是在程序运行时才被载入。***/

-force-debug-info 强制生成调试信息 (参数可选)/*** 这个参数是让Qt release版本也生成.pdb文件。这个文件有什么作用呢?它就是我们在release版本下设置了异常捕获信息函数,打印出错堆栈信息所必须的文件。如果程序没用开启异常捕获选项,是不需要开启这个参数的。***/

-opengl dynamic 指定opengl库 (参数可选) /*** 关于这个参数说明请参考doc.qt.io/qt-5/windows-requirements.html ***/

-platform win32-msvc 目标库运行平台

-skip 跳过该模块

-nomake 不编译该模块

-mp 启动多核编译

注:-skip和-nomake都可省略,但是-skip qtwebengine这个参数不能省略,qtwebengine模块有需要依赖的库,这里不跳过编译会失败。

编译

整体编译:make && make install

按需编译:我只需要基本的一些库,所以我执行的是nmake module-qtmultimedia;
 

等待configure命名执行完成后,输入nmake开始编译,如果结果没有错误,输入nmake install等待结束,完成。
注:期间尝试了很多组命令,都会编译失败,后来编译成功了,但是configure 设置的是release也是生成debug库,猜测是nmake clean 没有彻底执行成功,重新下载干净的源码重新来

编译出错解决

错误一:'fxc.exe' 不是内部或外部命令,也不是可运行的程序

猜测应该是d3d相关的配置不对或者没有,主要是编译qt3d库的时候

Microsoft (R) 程序维护实用工具 14.00.24245.0 版
版权所有 (C) Microsoft Corporation。  保留所有权利。

        cd d3d12\ && ( if not exist Makefile D:\Qt\Qt5.9.9\5.9.9\Src\qtbase\bin\qmake.exe -o Makefile D:\Qt\Qt5.9.9\5.9.9\Src\qtdeclarative\src\plugins\scenegraph\d3d12\d3d12.pro ) && "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\nmake.exe" -f Makefile

Microsoft (R) 程序维护实用工具 14.00.24245.0 版
版权所有 (C) Microsoft Corporation。  保留所有权利。

        "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\nmake.exe" -f Makefile.Release

Microsoft (R) 程序维护实用工具 14.00.24245.0 版
版权所有 (C) Microsoft Corporation。  保留所有权利。

        fxc.exe /nologo /E VS_VertexColor /T vs_5_0 /Fh vs_vertexcolor.hlslh shaders\vertexcolor.hlsl
'fxc.exe' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
NMAKE : fatal error U1077: “fxc.exe”: 返回代码“0x1”
Stop.
NMAKE : fatal error U1077: “"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\nmake.exe"”:  返回代码“0x2”
Stop.
NMAKE : fatal error U1077: “cd”: 返回代码“0x2”
Stop.
NMAKE : fatal error U1077: “cd”: 返回代码“0x2”
Stop.
NMAKE : fatal error U1077: “cd”: 返回代码“0x2”
Stop.
NMAKE : fatal error U1077: “cd”: 返回代码“0x2”
Stop.
NMAKE : fatal error U1077: “cd”: 返回代码“0x2”

解决:设置环境变量

C:\Program Files (x86)\Windows Kits\8.1\bin\x64下的fxc.exe的路径添加到环境变量 

msvc编译qt源码(qt6之前版本)_第2张图片

错误二.NMAKE:fatal error U1077.“cl.exe” return code 0xc0000135

产生原因:在安装visual studio的时候没有勾选注册环境变量导致的。

解决办法:在系统环境变量中加入visual studio的安装路径:vs安装路径\VC\Bin,以及vs安装路径\Common7\IDE

错误三.NMAKE:fatal error U1077. return code 0x2

产生原因:找不到代码文件中包含的头文件

解决办法:cmd下进入到vs安装路径\VC\Bin下,执行vcvars32,此时会执行vcvas32.bat自动为vs设置环境变量

错误四.NMAKE:fatal error U1077. return code 0x460

产生原因:你的工程中连接了一个lib文件,链接的时候却出现不能解析的外部符号。可能问题是你包含的lib是错的,或者有不兼容问题。我的问题就是后者,我的系统的32位的,但是链接了一个64位的lib.

解决办法:链接正确的lib

你可能感兴趣的:(qt,开发语言)