You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Actions编译无报错,为何未生成hello可执行文件?

问题:GitHub Actions编译C++项目后,未找到生成的hello可执行文件

我配置了GitHub Actions的C/C++ CI工作流,执行后Actions面板显示无报错,但找不到编译生成的hello可执行文件。相关配置如下:

工作流配置

name: C/C++ CI

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

jobs:
  build-and-test:
      runs-on: ubuntu-latest
      steps:
      - uses: actions/checkout@v2
      - name: install cppunit
        run: sudo apt install -y libcppunit-dev
      - name: configure
        run: ./configure
      - name: make
        run: make
      - name: make test
        run: make test

Makefile内容

all:
      g++ -std=c++17 hello.cpp -o hello
      g++ -std=c++17 helloTest.cpp -lcppunit -o helloTest

test:
      chmod +x hello
      ./helloTest

clean:
      $(RM) hello helloTest

请问为何未生成该可执行文件作为工作流输出?


原因及解决方案

核心原因

GitHub Actions的运行环境是临时容器,job执行完毕后整个环境会被销毁。你的工作流仅完成了编译和测试操作,但没有配置上传构建产物的步骤,所以编译出的hello文件在job结束后就被自动清理了,自然无法在外部找到。

解决步骤

在工作流的make test步骤之后,添加上传构建产物的动作,使用官方的actions/upload-artifact:

- name: 上传可执行文件
  uses: actions/upload-artifact@v4
  with:
    name: hello-executable
    path: hello
  • name:自定义上传产物的名称,方便后续识别
  • path:hello可执行文件的路径,如果文件在子目录中,需要调整为对应路径(比如./build/hello)

额外优化点

  1. 若项目没有configure脚本,可直接移除configure步骤,避免不必要的执行
  2. 测试步骤中的chmod +x hello可省略,g++编译生成的可执行文件默认已具备执行权限

内容的提问来源于stack exchange,提问作者Papus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 00:38:14