使用 Github Actions 为 Windows 编译 QT 应用程序时出错

Posted

技术标签:

【中文标题】使用 Github Actions 为 Windows 编译 QT 应用程序时出错【英文标题】:Error compiling a QT app for Windows with Github Actions 【发布时间】:2021-11-18 09:06:27 【问题描述】:

我试图让 Github Actions 在 Windows 上编译我的项目,但它失败了。在我的机器上编译时,它编译得很好。为什么在 Github Actions 上会失败?

我也尝试过使用 juppel/install-qt-action@v2.5.3 安装 QT,但我得到了同样的错误

该项目在 Mac 和 Linux 上编译良好​​p>

编译输出:

Info: creating stash file D:\a\dsda-launcher\dsda-launcher\dsda-launcher\build\.qmake.stash
24
C:/ProgramData/Chocolatey/lib/make/tools/install/bin/make.exe -f Makefile.Release
25
make[1]: Entering directory 'D:/a/dsda-launcher/dsda-launcher/dsda-launcher/build'
26
'C:\Qt\5.15.2\mingw81_64\bin\uic.exe' ../mainwindow.ui -o ui_mainwindow.h
27
g++ -c -fno-keep-inline-dllexport -O2 -std=gnu++11 -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DAPP_NAME=dsda-launcher -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CONCURRENT_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I../../dsda-launcher -I. -IC:/Qt/5.15.2/mingw81_64/include -IC:/Qt/5.15.2/mingw81_64/include/QtWidgets -IC:/Qt/5.15.2/mingw81_64/include/QtGui -IC:/Qt/5.15.2/mingw81_64/include/QtANGLE -IC:/Qt/5.15.2/mingw81_64/include/QtNetwork -IC:/Qt/5.15.2/mingw81_64/include/QtConcurrent -IC:/Qt/5.15.2/mingw81_64/include/QtCore -Irelease -I. -I/include -IC:/Qt/5.15.2/mingw81_64/mkspecs/win32-g++  -o release/main.o ../main.cpp
28
g++ -c -fno-keep-inline-dllexport -O2 -std=gnu++11 -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DAPP_NAME=dsda-launcher -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CONCURRENT_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I../../dsda-launcher -I. -IC:/Qt/5.15.2/mingw81_64/include -IC:/Qt/5.15.2/mingw81_64/include/QtWidgets -IC:/Qt/5.15.2/mingw81_64/include/QtGui -IC:/Qt/5.15.2/mingw81_64/include/QtANGLE -IC:/Qt/5.15.2/mingw81_64/include/QtNetwork -IC:/Qt/5.15.2/mingw81_64/include/QtConcurrent -IC:/Qt/5.15.2/mingw81_64/include/QtCore -Irelease -I. -I/include -IC:/Qt/5.15.2/mingw81_64/mkspecs/win32-g++  -o release/mainwindow.o ../mainwindow.cpp
29
../mainwindow.cpp: In function 'QString lowerCase(std::__cxx11::string)':
30
../mainwindow.cpp:77:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' aka 'long long unsigned int' [-Wsign-compare]
31
     for(int i=0;i<word.length();i++)
32
                 ~^~~~~~~~~~~~~~
33
../mainwindow.cpp: In constructor 'MainWindow::MainWindow(QWidget*)':
34
../mainwindow.cpp:211:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' aka 'long long unsigned int' [-Wsign-compare]
35
                     for(int i=0;i<tp.length();i++) // Loop the chars to find the 4 quotes
36
                                 ~^~~~~~~~~~~~
37
../mainwindow.cpp:266:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' aka 'long long unsigned int' [-Wsign-compare]
38
                             for(int i=0;i<tp.length();i++)
39
                                         ~^~~~~~~~~~~~
40
../mainwindow.cpp:308:46: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' aka 'long long unsigned int' [-Wsign-compare]
41
                                 for(int i=0;i<tp.length();i++)
42
                                             ~^~~~~~~~~~~~
43
../mainwindow.cpp: In member function 'void MainWindow::on_LaunchGameButton_clicked(bool, bool)':
44
../mainwindow.cpp:881:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' aka 'long long unsigned int' [-Wsign-compare]
45
             for(int i=0; i<dehFiles.length();i++)
46
                          ~^~~~~~~~~~~~~~~~~~
47
../mainwindow.cpp:893:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' aka 'long long unsigned int' [-Wsign-compare]
48
             for(int i=0; i<files.length();i++)
49
                          ~^~~~~~~~~~~~~~~
50
In file included from C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/include/windows.h:65,
51
                 from ../mainwindow.cpp:1068:
52
C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/include/excpt.h:14:8: error: expected unqualified-id before string constant
53
 extern "C" 
54
        ^~~
55
In file included from C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/include/minwindef.h:6,
56
                 from C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/include/windef.h:8,
57
                 from C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/include/windows.h:69,
58
                 from ../mainwindow.cpp:1068:
59
C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/include/specstrings.h:18:8: error: expected unqualified-id before string constant
60
 extern "C" 
61
        ^~~
62
In file included from C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/include/windef.h:8,
63
                 from C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/include/windows.h:69,
64
                 from ../mainwindow.cpp:1068:
65
C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/include/minwindef.h:19:8: error: expected unqualified-id before string constant
66
 extern "C" 
67
        ^~~
68
In file included from C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/x86intrin.h:27,
69
                 from C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/include/winnt.h:1554,
70
                 from C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/include/minwindef.h:163,
71
                 from C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/include/windef.h:8,
72
                 from C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/include/windows.h:69,
73
                 from ../mainwindow.cpp:1068:
74
C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/ia32intrin.h:55:25: error: expected '' before end of line
75
 #pragma GCC push_options
76
                         ^
77
../mainwindow.cpp:751:1: note: to match this ''
78
 
79
 ^
80
In file included from C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/x86intrin.h:27,
81
                 from C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/include/winnt.h:1554,
82
                 from C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/include/minwindef.h:163,
83
                 from C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/include/windef.h:8,
84
                 from C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/include/windows.h:69,
85
                 from ../mainwindow.cpp:1068:
86
C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/ia32intrin.h: At global scope:
87
C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/ia32intrin.h:55:25: error: expected declaration before end of line
88
 #pragma GCC push_options
89
                         ^
90
make[1]: *** [Makefile.Release:725: release/mainwindow.o] Error 1
91
make[1]: Leaving directory 'D:/a/dsda-launcher/dsda-launcher/dsda-launcher/build'
92
make: *** [Makefile:45: release] Error 2

Github 操作代码:

steps:
      - name: Install qt
        run: |
          choco install qt5-default
      - uses: actions/checkout@v2
      - name: build
        run: |
          C:\Qt\5.15.2\mingw81_64\bin\qmake.exe ..
          make.exe

【问题讨论】:

【参考方案1】:

找到了解决办法。在包含任何其他标题之前,我必须致电 #include &lt;windows.h&gt;。我不知道为什么,但它确实有效。

https://forum.qt.io/topic/38780/solved-errors-with-windows-h

【讨论】:

以上是关于使用 Github Actions 为 Windows 编译 QT 应用程序时出错的主要内容,如果未能解决你的问题,请参考以下文章

SonarCloud 代码覆盖率在 GitHub Actions 构建中保持为 0.0

使用 GitHub Actions 从私有 GitHub 存储库安装 npm 模块

检查 GitHub Actions 工作流程中的对象是不是为空

在线工作坊 | 使用 GitHub Actions 实现自动化开发

github Actions 使用方法

在 GitHub Actions 中使用上下文表达式中的变量