🙌

GitHub Actions で mingw でビルドした実行ファイルが動かない

2022/07/01に公開

事象

GitHub Actions の windows-latestwindows-2022 になってから Mingw の g++ でビルドしたものが動かなくなってしまいました。

下記のようなワークフローを実行すると windows-2022 の cmdpwsh では「Process completed with exit code -1073741511.」というようなエラーでコケてしまいます。vector が原因のようです。

name: Mingw

on:
  push:
    branches:
      - master
  workflow_dispatch:

jobs:
  hello:
    runs-on: ${{ matrix.runs-on }}
    strategy:
      fail-fast: false
      matrix:
        runs-on: ["windows-2019", "windows-2022"]
    steps:
      - name: g++ version
        run: g++ -v
      - name: Crete file
        run: |
          '
          #include <cstdio>
          #include <vector>

          using namespace std;

          int main(int, char* argv[]) {
              vector<int> a(4);
              printf("%d\n", a.size());
              return 0;
          }
          ' > hello.cpp
      - name: Compile
        run: g++ -o hello hello.cpp
      - run: ./hello
        shell: bash
        if: always()
      - run: hello
        shell: cmd
        if: always()
      - run: ./hello
        shell: pwsh
        if: always()

結論

-static で静的リンクにしてビルドする。

動的リンクにしたい場合は Git Bash で動かしたらOK。
mingw にパスを通しても良し。

name: Mingw

on:
  push:
    branches:
      - master
  workflow_dispatch:

jobs:
  hello:
    runs-on: ${{ matrix.runs-on }}
    strategy:
      fail-fast: false
      matrix:
        runs-on: ["windows-2019", "windows-2022"]
    steps:
      - name: g++ version
        run: g++ -v
      - name: Crete file
        run: |
          '
          #include <cstdio>
          #include <vector>

          using namespace std;

          int main(int, char* argv[]) {
              vector<int> a(4);
              printf("%d\n", a.size());
              return 0;
          }
          ' > hello.cpp

      - name: Compile static
        run: g++ -static -o hello_static hello.cpp
      - run: ./hello_static

      - name: Compile dynamic
        run: g++ -o hello_dynamic hello.cpp
      - name: Git Bash で動かす
        run: ./hello_dynamic
        shell: bash
      - name: Path を通す
        shell: pwsh
        run: |
          $env:Path = "C:\Program Files\Git\mingw64\bin;$env:Path"
          ./hello_dynamic

調査

動的リンクに必要な C:\Program Files\Git\mingw64\bin\lib*.dll のあたりがGit Bash だけ Path が通っているのが原因かとも思ったのですが、pwsh などでも Path は通っているようです。

さらに調べると、C:\Strawberry\c\bin\lib*.dll の古いバージョンのものが使われているのが原因だと判明しました。

Git Bash だと先頭に /mingw64/bin が追加されるので Mingw のdll が使われるため正常に動かせたようです。

Path の情報

Path

      - run: $env:Path
        shell: pwsh

で出力

C:\Program Files\PowerShell\7
C:\Program Files\MongoDB\Server\5.0\bin
C:\aliyun-cli
C:\vcpkg
C:\Program Files (x86)\NSIS\
C:\tools\zstd
C:\Program Files\Mercurial\
C:\hostedtoolcache\windows\stack\2.7.5\x64
C:\cabal\bin
C:\\ghcup\bin
C:\tools\ghc-9.2.3\bin
C:\Program Files\dotnet
C:\mysql\bin
C:\Program Files\R\R-4.2.1\bin\x64
C:\SeleniumWebDrivers\GeckoDriver
C:\Program Files (x86)\sbt\bin
C:\Program Files (x86)\GitHub CLI
C:\Program Files\Git\bin
C:\Program Files (x86)\pipx_bin
C:\npm\prefix
C:\hostedtoolcache\windows\go\1.17.11\x64\bin
C:\hostedtoolcache\windows\Python\3.9.13\x64\Scripts
C:\hostedtoolcache\windows\Python\3.9.13\x64
C:\hostedtoolcache\windows\Ruby\3.0.4\x64\bin
C:\tools\kotlinc\bin
C:\hostedtoolcache\windows\Java_Temurin-Hotspot_jdk\8.0.332-9\x64\bin
C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin
C:\ProgramData\kind
C:\Program Files\Microsoft\jdk-11.0.12.7-hotspot\bin
C:\Windows\system32
C:\Windows
C:\Windows\System32\Wbem
C:\Windows\System32\WindowsPowerShell\v1.0\
C:\Windows\System32\OpenSSH\
C:\Program Files\dotnet\
C:\ProgramData\Chocolatey\bin
C:\Program Files\Docker
C:\Program Files\PowerShell\7\
C:\Program Files\Microsoft\Web Platform Installer\
C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\
C:\Program Files\Microsoft SQL Server\150\Tools\Binn\
C:\Program Files\OpenSSL\bin
C:\Strawberry\c\bin
C:\Strawberry\perl\site\bin
C:\Strawberry\perl\bin
C:\ProgramData\chocolatey\lib\pulumi\tools\Pulumi\bin
C:\Program Files\TortoiseSVN\bin
C:\Program Files\CMake\bin
C:\ProgramData\chocolatey\lib\maven\apache-maven-3.8.6\bin
C:\Program Files\Microsoft Service Fabric\bin\Fabric\Fabric.Code
C:\Program Files\Microsoft SDKs\Service Fabric\Tools\ServiceFabricLocalClusterManager
C:\Program Files\nodejs\
C:\Program Files\Git\cmd
C:\Program Files\Git\mingw64\bin
C:\Program Files\Git\usr\bin
C:\Program Files\GitHub CLI\
c:\tools\php
C:\Program Files (x86)\sbt\bin
C:\SeleniumWebDrivers\ChromeDriver\
C:\SeleniumWebDrivers\EdgeDriver\
C:\Program Files\Amazon\AWSCLIV2\
C:\Program Files\Amazon\SessionManagerPlugin\bin\
C:\Program Files\Amazon\AWSSAMCLI\bin\
C:\Program Files\Microsoft SQL Server\130\Tools\Binn\
C:\Program Files\LLVM\bin
C:\Users\runneradmin\.dotnet\tools
C:\Users\runneradmin\.cargo\bin
C:\Users\runneradmin\AppData\Local\Microsoft\WindowsApps

Path の通った dll

      - run: $env:Path -split ';' | ? { Test-Path $_ } | %{ dir "$_\lib*.dll" }
        shell: pwsh

で出力


    Directory: C:\mysql\bin
Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---           3/23/2022  8:22 AM        3449536 libcrypto-1_1-x64.dll
-a---           3/23/2022  8:22 AM        1847464 libmecab.dll
-a---           3/23/2022  8:22 AM        6248128 libprotobuf-debug.dll
-a---           3/23/2022  8:22 AM        1407176 libprotobuf-lite-debug.dll
-a---           3/23/2022  8:22 AM         606392 libprotobuf-lite.dll
-a---           3/23/2022  8:22 AM        2854576 libprotobuf.dll
-a---           3/23/2022  8:22 AM         695992 libssl-1_1-x64.dll
    Directory: C:\Windows\system32
Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---           9/25/2018  6:08 PM        3394560 libcrypto-1_1-x64.dll
-a---            5/7/2021  3:17 PM        1687040 libcrypto.dll
-a---           6/10/2022  7:52 PM         699272 libomp140.x86_64.dll
-a---           6/10/2022  7:52 PM        2964912 libomp140d.x86_64.dll
-a---           9/25/2018  6:08 PM         679424 libssl-1_1-x64.dll
    Directory: C:\Program Files\Docker
Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---            2/2/2021  5:18 PM        2454016 libeay32.dll
-a---           5/11/2017 10:32 PM          56978 libwinpthread-1.dll
    Directory: C:\Program Files\OpenSSL\bin
Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---           9/25/2018  6:08 PM        3394560 libcrypto-1_1-x64.dll
-a---           9/25/2018  6:08 PM         679424 libssl-1_1-x64.dll
    Directory: C:\Strawberry\c\bin
Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---           3/14/2019 10:36 PM          32768 libatomic-1.dll
-a---           5/22/2019  4:14 PM          77331 libbz2-1__.dll
-a---           5/22/2019  4:14 PM          17700 libcharset-1__.dll
-a---           1/24/2021 11:52 AM        2735253 libcrypto-1_1-x64__.dll
-a---           5/22/2019  4:14 PM        1727312 libdb-6.2__.dll
-a---           5/22/2019  4:14 PM         229768 libexpat-1__.dll
-a---           5/22/2019  4:14 PM          95006 libexslt-0__.dll
-a---            2/7/2020  4:15 PM          36083 libffi-7__.dll
-a---           5/22/2019  4:15 PM         276168 libfontconfig-1__.dll
-a---           5/22/2019  4:15 PM         674627 libfreetype-6__.dll
-a---           7/12/2020  7:34 PM         117986 libfribidi-0__.dll
-a---           3/14/2019 10:36 PM          76288 libgcc_s_seh-1.dll
-a---           5/22/2019  4:15 PM         364069 libgd-3__.dll
-a---           5/22/2019  4:14 PM          22590 libgdbm_compat-4__.dll
-a---           5/22/2019  4:14 PM          57906 libgdbm-6__.dll
-a---           5/22/2019  4:15 PM          38328 libgif-7__.dll
-a---            2/9/2020  5:43 PM         242000 libglut-0__.dll
-a---           3/14/2019 10:36 PM         157184 libgomp-1.dll
-a---           5/22/2019  4:15 PM         151688 libgraphite2__.dll
-a---           5/22/2019  4:15 PM        1047675 libharfbuzz-0__.dll
-a---           5/22/2019  4:15 PM         366738 libharfbuzz-subset-0__.dll
-a---           5/22/2019  4:14 PM          40786 libhistory8__.dll
-a---           5/22/2019  4:14 PM         949225 libiconv-2__.dll
-a---           5/22/2019  4:15 PM         214173 libidn2-0__.dll
-a---           5/22/2019  4:15 PM         215481 libjpeg-9__.dll
-a---           5/22/2019  4:14 PM         154319 liblzma-5__.dll
-a---           9/28/2016  8:16 PM        5297152 libmysql__.dll
-a---           5/22/2019  4:15 PM         220683 libpng16-16__.dll
-a---           5/22/2019  4:15 PM         384135 libpq__.dll
-a---           3/14/2019 10:36 PM         334848 libquadmath-0.dll
-a---           5/22/2019  4:14 PM         219170 libreadline8__.dll
-a---           5/22/2019  4:14 PM         228795 libssh2-1__.dll
-a---           1/24/2021 11:52 AM         548349 libssl-1_1-x64__.dll
-a---           3/14/2019 10:36 PM          17408 libssp-0.dll
-a---           3/14/2019 10:36 PM        1424384 libstdc++-6.dll
-a---           5/22/2019  4:15 PM         262528 libt1-5__.dll
-a---           5/22/2019  4:14 PM          22509 libtermcap-0__.dll
-a---           5/22/2019  4:15 PM         455363 libtiff-5__.dll
-a---           5/22/2019  4:15 PM          20525 libtiffxx-5__.dll
-a---           5/22/2019  4:15 PM        1816226 libunistring-2__.dll
-a---           7/12/2020  7:33 PM         451840 libwebp-7__.dll
-a---           7/12/2020  7:33 PM          25544 libwebpdemux-2__.dll
-a---           7/12/2020  7:33 PM          50019 libwebpmux-3__.dll
-a---           3/14/2019 10:36 PM          52224 libwinpthread-1.dll
-a---           5/22/2019  4:14 PM        1297680 libxml2-2__.dll
-a---           5/22/2019  4:15 PM          64512 libXpm__.dll
-a---           5/22/2019  4:14 PM         240987 libxslt-1__.dll
    Directory: C:\Strawberry\perl\bin
Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---           3/14/2019 10:36 PM          76288 libgcc_s_seh-1.dll
-a---           3/14/2019 10:36 PM        1424384 libstdc++-6.dll
-a---           3/14/2019 10:36 PM          52224 libwinpthread-1.dll
    Directory: C:\Program Files\TortoiseSVN\bin
Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---            4/9/2022  2:32 PM         216144 libapr_tsvn.dll
-a---            4/9/2022  2:32 PM         287312 libaprutil_tsvn.dll
-a---            4/9/2022  2:33 PM         101456 libsasl.dll
-a---            4/9/2022  2:33 PM        6958672 libsvn_tsvn.dll
    Directory: C:\Program Files\Microsoft Service Fabric\bin\Fabric\Fabric.Code
Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---           5/23/2022  6:48 AM        5189536 libcrypto-3-x64.dll
-a---           5/23/2022  6:48 AM         498576 libprotobuf-lite.dll
-a---           5/23/2022  6:48 AM        2448792 libprotobuf.dll
-a---           5/23/2022  6:48 AM        2193304 libprotoc.dll
-a---           5/23/2022  6:48 AM         782744 libssl-3-x64.dll
    Directory: C:\Program Files\Git\mingw64\bin
Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---            5/9/2022  1:44 PM         142885 libbrotlicommon.dll
-a---            5/9/2022  1:44 PM          52364 libbrotlidec.dll
-a---            5/9/2022  1:44 PM          99146 libbz2-1.dll
-a---            5/9/2022  1:44 PM         125026 libcares-5.dll
-a---            5/9/2022  1:44 PM        2799260 libcrypto-1_1-x64.dll
-a---            5/9/2022  1:44 PM         679580 libcurl-4.dll
-a---            5/9/2022  1:44 PM         203594 libexpat-1.dll
-a---            5/9/2022  1:44 PM          84147 libgcc_s_seh-1.dll
-a---            5/9/2022  1:44 PM         656906 libgmp-10.dll
-a---            5/9/2022  1:44 PM         275300 libhogweed-6.dll
-a---            5/9/2022  1:44 PM        1058528 libiconv-2.dll
-a---            5/9/2022  1:44 PM         171299 libidn2-0.dll
-a---            5/9/2022  1:44 PM         136724 libintl-8.dll
-a---            5/9/2022  1:44 PM          78930 libjansson-4.dll
-a---            5/9/2022  1:44 PM         529915 libjemalloc.dll
-a---            5/9/2022  1:44 PM         154261 liblzma-5.dll
-a---            5/9/2022  1:44 PM         289910 libnettle-8.dll
-a---            5/9/2022  1:44 PM         178264 libnghttp2-14.dll
-a---            5/9/2022  1:44 PM        1077452 libp11-kit-0.dll
-a---            5/9/2022  1:44 PM         281695 libpcre-1.dll
-a---            5/9/2022  1:44 PM         618344 libpcre2-8-0.dll
-a---            5/9/2022  1:44 PM          41752 libpcreposix-0.dll
-a---            5/9/2022  1:44 PM         270123 libssh2-1.dll
-a---            5/9/2022  1:44 PM         562332 libssl-1_1-x64.dll
-a---            5/9/2022  1:44 PM          43431 libssp-0.dll
-a---            5/9/2022  1:44 PM        1966804 libstdc++-6.dll
-a---            5/9/2022  1:44 PM          92313 libtre-5.dll
-a---            5/9/2022  1:44 PM        1934495 libunistring-2.dll
-a---            5/9/2022  1:44 PM          58621 libwinpthread-1.dll
-a---            5/9/2022  1:44 PM        1358075 libxml2-2.dll
-a---            5/9/2022  1:44 PM         830348 libzstd.dll
    Directory: C:\tools\php
Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---            6/7/2022 10:23 PM        3478528 libcrypto-1_1-x64.dll
-a---            6/7/2022 10:23 PM          42496 libenchant2.dll
-a---            6/7/2022 10:23 PM         282112 libpq.dll
-a---            6/7/2022 10:23 PM         194560 libsasl.dll
-a---            6/7/2022 10:23 PM         303616 libsodium.dll
-a---            6/7/2022 10:23 PM        1619456 libsqlite3.dll
-a---            6/7/2022 10:23 PM         380928 libssh2.dll
-a---            6/7/2022 10:23 PM         688128 libssl-1_1-x64.dll
    Directory: C:\Program Files\Amazon\AWSCLIV2
Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---           6/24/2022  6:40 PM        3439512 libcrypto-1_1.dll
-a---           6/24/2022  6:40 PM          32792 libffi-7.dll
-a---           6/24/2022  6:40 PM         698784 libssl-1_1.dll
    Directory: C:\Program Files\LLVM\bin
Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---            2/2/2022  5:13 PM       83801600 libclang.dll
-a---            2/2/2022  5:36 PM         701440 libiomp5md.dll
-a---            2/2/2022  5:15 PM      105050624 liblldb.dll
-a---            2/2/2022  5:03 PM         701440 libomp.dll

修正予定は?

Strawberry を除外するのは無理らしいです
https://github.com/actions/virtual-environments/issues/5459

GitHubで編集を提案

Discussion