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

文件夹结构

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



附注
自行下载源代码并解压,修改后的脚本在我的机器上运行花了1小时45分。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值