Windows下MinGW编译静态Qt I 之实践

来源:互联网 发布:马步 骑士巡游 算法 编辑:程序博客网 时间:2024/05/08 19:31

文件夹结构

Qt动态环境安装路径 D:\Qt\MinGW\
Qt静态环境路径 D:\Qt\MinGW\Static
Qt源代码目录   D:\Qt\MinGW\Static\src\ //解压源代码到此目录下,长这个样子



修改脚本

function Main{    # Check that 7zip is installed. We use it to expand the downloaded archive.    #[void] (Get-7zip) #手动解压,跳过验证7-zip    # Get Qt source file name from URL.    $QtSrcFileName = Split-Path -Leaf $QtSrcUrl    # If Qt version is not specified on the command line, try to extract the value.    if (-not $QtVersion) {        $QtVersion = $QtSrcFileName -replace "`.[^`.]*$",''        $QtVersion = $QtVersion -replace 'qt-',''        $QtVersion = $QtVersion -replace 'everywhere-',''        $QtVersion = $QtVersion -replace 'opensource-',''        $QtVersion = $QtVersion -replace 'src-',''        $QtVersion = $QtVersion -replace '-src',''    }    Write-Output "Building static Qt version $QtVersion"    # Qt installation directory.    $QtDir = "$QtStaticDir\$QtVersion"    # Get MinGW root directory, if not specified on the command line.    if (-not $MingwDir) {        # Search all instances of gcc.exe from C:\Qt prebuilt environment.        $GccList = @(Get-ChildItem -Path C:\Qt\*\Tools\mingw*\bin\gcc.exe | ForEach-Object FullName | Sort-Object)        if ($GccList.Length -eq 0) {            Exit-Script "MinGW environment not found, no Qt prebuilt version?"        }        $MingwDir = (Split-Path -Parent (Split-Path -Parent $GccList[$GccList.Length - 1]))    }    Write-Output "Using MinGW from $MingwDir"    # Build the directory tree where the static version of Qt will be installed.    #Create-Directory $QtStaticDir\src    #已手动创建,且源代码已解压到此路径下    Create-Directory $QtDir    # Download the Qt source package if not yet done.    #Download-File $QtSrcUrl $QtStaticDir\src\$QtSrcFileName #跳过下载代码包    # Directory of expanded packages.    #$QtSrcDir = "$QtStaticDir\src\$((Get-Item $QtStaticDir\src\$QtSrcFileName).BaseName)"    $QtSrcDir = "$QtStaticDir\src\qt-everywhere-opensource-src-5.5.0" #手动指定源代码目录    # Expand archives if not yet done    #Expand-Archive $QtStaticDir\src\$QtSrcFileName $QtStaticDir\src $QtSrcDir #跳过解压源代码包          ...以下略...}


执行脚本


在PowerShell中执行脚本,
PS D:\Qt> .\windows-build-qt-static.ps1 -QtStaticDir 'D:\Qt\MinGW\Static' -QtVersion 'Qt5.5.0' -MingwDir 'D:\Qt\MinGW\Qt5.5.0\Tools\mingw492_32\'-QtStaticDir 'D:\Qt\MinGW\Static'    #默认为c:\Qt\Static-QtVersion 'Qt5.5.0'                 #脚本解析为5.5.0,运行过程出现报错。手动指定版本号解决了。-MingwDir 'D:\Qt\MinGW\Qt5.5.0\Tools\mingw492_32\' #若不指定,脚本会从默认安装路径找C:\Qt\*\Tools\mingw*\bin\gcc.exe


遇到的问题

PowerShell执行脚本提示“无法加载文件”

Set-ExecutionPolicy RemoteSigned

参考powershell-无法加载文件,因为在此系统中禁止执行脚本。


附注
自行下载源代码并解压,修改后的脚本在我的机器上运行花了1小时45分。
0 0
原创粉丝点击