Linking Qt with github actions using mingw

Viewed 574

I'm using the jurplel/install-qt-action with itself uses aqtinstall under the covers to configure a github action to build a basic qt application against mingw53 (also tried mingw73 both win32 and win64) with obviously a windows build agent.

Build always fails on the link:

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

The desktop QtCreator version of this minimal console app builds fine against exactly the same package versions. Have tried lots of combinations of versions and (potential) LIB/static flags but still no dice. The lack of any examples of representative mingw Qt builds on github makes me think that this is just an untested and always failing path but I am desperate to get it working! Any ideas for other thing to try? Project is here along with history of all the build failures:

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

1 Answers

Ok it was pretty simple in the end but took me an age to conceptually work out.

At time of writing default windows-latest github actions agents come with mingw (8.2) and strawberryperl installed as chocolatey packages. Both of these have g++.exes (64-bit) which contaminate the path. Additionally there is no chocolatey package which I could find that does mingw 32-bit (either 5.3 or 7.3) which I could use against 32-bit Qt.

However you can uninstall the choco packages mentioned above and either go fully 64-bit or if you want 32-bit you can install the numworks/setup-msys2 action as follows:

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.]
Related