How can I run a compiled .exe executable in GitHub CI workflow with makefiles on a windows environment?

huangapple go评论67阅读模式
英文:

How can I run a compiled .exe executable in GitHub CI workflow with makefiles on a windows environment?

问题

I am currently implementing a simple test program for my small project in GitHub, But I'm having trouble running that same test program in the CI workflow in a runs-on: windows-latest environment.

For the linux job I don't have any problem.

But I can't figure out how to run the executable in windows. it's giving me an exit code error 1:
mingw32-make: *** [makefile:33: run_test] Error -1073741511 Error: Process completed with exit code 1.

Here is the .yml file that I'm currently using.

name: tests

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  linux:

    runs-on: ubuntu-latest
    
    steps:
    - uses: actions/checkout@v2

    - name: compile tests
      run: make test CXX=g++

    - name: run tests
      run: make run_test

  windows:

    runs-on: windows-latest

    steps:
    - uses: actions/checkout@v2
    - name: compile tests
      run: make test CXX=g++

    - name: run tests
      run: make run_test

This is the portion of the makefile for running the test program.

run_test:
	@echo running test program
ifeq ($(OS), Linux)
	./$(OUTPUT_NAME).$(EXTENSION)
else
	.\$(OUTPUT_NAME)
endif

I also tried to edit the line in the makefile that runs the executable to other forms like given below:

  • .\$(OUTPUT_NAME).$(EXTENSION)
  • ./$(OUTPUT_NAME).$(EXTENSION)
  • ./$(OUTPUT_NAME)
  • ./$(OUTPUT_NAME)
  • $(OUTPUT_NAME).$(EXTENSION)
  • $(OUTPUT_NAME)

But still these attempts are giving me either an exit error code 1 or error exit code 2.

I also tried to run

    - name: run tests
      shell: cmd
      run: make run_test

and just use $(OUTPUT_NAME) in the makefile but still no success.

[EDIT]

The compilation for windows-latest environment (compile test) works perfectly fine, The only problem that I encounter is I cannot run that compiled executable.

英文:

I am currently implementing a simple test program for my small project in GitHub, But I'm having trouble running that same test program in the CI workflow in a runs-on: windows-latest environment.

For the linux job I don't have any problem.

But I can't figure out how to run the executable in windows. it's giving me an exit code error 1:
mingw32-make: *** [makefile:33: run_test] Error -1073741511
Error: Process completed with exit code 1.

Here is the .yml file that I'm currently using.

name: tests

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  linux:

    runs-on: ubuntu-latest
    
    steps:
    - uses: actions/checkout@v2

    - name: compile tests
      run: make test CXX=g++

    - name: run tests
      run: make run_test

  windows:

    runs-on: windows-latest

    steps:
    - uses: actions/checkout@v2
    - name: compile tests
      run: make test CXX=g++

    - name: run tests
      run: make run_test

This is the portion of the makefile for running the test program.

run_test:
	@echo running test program
ifeq ($(OS), Linux)
	./$(OUTPUT_NAME).$(EXTENSION)
else
	.\$(OUTPUT_NAME)
endif

I also tried to edit the line in the makefile that runs the executable to other forms like given below:

  • .\$(OUTPUT_NAME).$(EXTENSION)
  • ./$(OUTPUT_NAME).$(EXTENSION)
  • ./$(OUTPUT_NAME)
  • ./$(OUTPUT_NAME)
  • $(OUTPUT_NAME).$(EXTENSION)
  • $(OUTPUT_NAME)

But still these attempts is giving me either an exit error code 1 or error exit code 2.

I also tried to run

    - name: run tests
      shell: cmd
      run: make run_test

and just use $(OUTPUT_NAME) in the makefile but still no success.

[EDIT]

The compilation for windows-latest environment (compile test) works perfectly fine, The only problem that I encounter is I cannot run that compiled executable.

答案1

得分: 0

GitHubs windows-latest,目前默认相当于 windows-2022(在撰写时),默认情况下不包括环境变量中所需的 DLL 路径,因此当我们编译程序时,实际上会生成一个无法在执行时运行的无效可执行文件。

  • GitHub 问题链接:https://github.com/actions/runner-images/issues/6103
  • GitHub 问题链接:https://github.com/allanlw/hphpc-docker/issues/4
  • GitHub 问题链接:https://github.com/actions/runner-images/issues/6412

在上述 GitHub 问题中,一些建议手动添加这些 DLL 可能会修复问题。

我们还可以使用较旧的 windows-2019 作为我们的 runner,而不是使用 windows-latest,因为这个 runner 默认情况下包含了正确编译和运行我们的可执行文件所需的 DLL 文件,这是我见过的最简单的解决方案。

name: tests

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  windows:

    # ...

    runs-on: windows-2019

    # ...

英文:

GitHubs windows-latest which is currently equivalent to windows-2022 (at the time of writing) by default does not include the necessary DLL paths needed in the environment variables, so when we compile our program it actually produces an invalid executable that will not run when executed.

In the GitHub issues above, some are suggesting to manually add these DLLs by yourself which could fix the problem.

We can also use an older windows-2019 as our runner instead of windows-latest since this runner by default has the necessary DLL files needed to correctly compile and run our executable, this is the easiest solution that I have seen.

name: tests

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  windows:

    # ...

    runs-on: windows-2019

    # ...

huangapple
  • 本文由 发表于 2023年2月24日 09:29:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75551871.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定