首页 > 解决方案 > 使用 mingw 将 Qt 与 github 操作链接

问题描述

我正在使用 juppel/install-qt-action 本身使用 aqtinstall 在幕后配置一个 github 操作来构建一个针对 mingw53 的基本 qt 应用程序(也尝试了 win32 和 win64 的 mingw73),显然是一个 windows 构建代理。

链接上的构建总是失败:

C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'D:/a/qt-github-console/qt-github-console'
g++ -c -fno-keep-inline-dllexport -g -std=gnu++11 -Wall -W -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_CORE_LIB -I. -I../Qt/5.11.3/mingw53_32/include -I../Qt/5.11.3/mingw53_32/include/QtCore -Idebug -I../Qt/5.11.3/mingw53_32/mkspecs/win32-g++  -o debug/main.o main.cpp
g++ -Wl,-subsystem,console -mthreads -o debug/qt-github-console.exe debug/main.o  -LD:/a/qt-github-console/Qt/5.11.3/mingw53_32/lib D:/a/qt-github-console/Qt/5.11.3/mingw53_32/lib/libQt5Cored.a 
debug/main.o: In function `main':
D:\a\qt-github-console\qt-github-console/main.cpp:5: undefined reference to `__imp__ZN16QCoreApplicationC1ERiPPci'
D:\a\qt-github-console\qt-github-console/main.cpp:7: undefined reference to `__imp__ZN16QCoreApplication4execEv'
D:\a\qt-github-console\qt-github-console/main.cpp:5: undefined reference to `__imp__ZN16QCoreApplicationD1Ev'
D:\a\qt-github-console\qt-github-console/main.cpp:5: undefined reference to `__imp__ZN16QCoreApplicationD1Ev'
collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: *** [Makefile.Debug:63: debug/qt-github-console.exe] Error 1
mingw32-make[1]: Leaving directory 'D:/a/qt-github-console/qt-github-console'
mingw32-make: *** [Makefile:36: debug] Error 2

这个最小控制台应用程序的桌面 QtCreator 版本可以针对完全相同的包版本构建良好。已经尝试了很多版本和(潜在的)LIB/静态标志的组合,但仍然没有骰子。缺乏任何在 github 上构建的代表性 mingw Qt 示例让我认为这只是一条未经测试且总是失败的路径,但我迫切希望让它发挥作用!有什么想法可以尝试吗?项目与所有构建失败的历史一起在这里:

https://github.com/bowniewk/qt-github-console

标签: qtgithublinkercontinuous-integration

解决方案


好的,最后它很简单,但我花了很长时间才从概念上解决问题。

在编写默认的 windows-latest github 操作代理时,mingw (8.2) 和草莓perl 作为巧克力包安装。这两个都有 g++.exes(64 位),会污染路径。此外,我找不到可以用于 32 位 Qt 的 mingw 32 位(5.3 或 7.3)的巧克力包。

但是,您可以卸载上面提到的 choco 包,或者完全进入 64 位,或者如果您想要 32 位,您可以安装 numworks/setup-msys2 操作,如下所示:

name: CI

env:
  QT_VERSION:     "5.12.7"
  MINGW_VERSION:  "win32_mingw73"
  MINGW_PATH:     "mingw73_32"

on: [push]

jobs:
  build:
    runs-on: windows-latest
    steps:

    - name: Install correct version of mingw
      run: |
        choco uninstall mingw --force
        choco uninstall strawberryperl --force
    - uses: numworks/setup-msys2@v1
      with:
        msystem: MINGW32

    - name: Install Qt
      uses: jurplel/install-qt-action@v2.5.3
      with:
        version: ${{ env.QT_VERSION }}
        arch:    ${{ env.MINGW_VERSION }}
        extra:   --external 7z

    - uses: actions/checkout@v1

    [etc.]

推荐阅读