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

GitHub构建依赖子模块的C项目XYZ失败:修正PRT变量路径

Fix: GitHub Build Fails to Find ABC Submodule Path

Let's break down your problem first: your local build works fine, but GitHub CI fails because GitHub Actions doesn't automatically pull Git submodules by default, and your hardcoded PRT variable can't adapt to the slightly different directory structure in GitHub's build environment (like the XYZ @ 324354 folder name you mentioned). Here's how to fix it step by step:

1. Ensure GitHub Actions Pulls the Submodule

First, update your GitHub Actions workflow file (usually .github/workflows/build.yml) to explicitly fetch the ABC submodule during checkout. Add the submodules: 'true' option to the checkout step:

steps:
  - name: Checkout code
    uses: actions/checkout@v4
    with:
      submodules: 'true'  # Fetch all registered submodules
      fetch-depth: 0      # Optional: needed if your submodule requires full commit history

Without this step, the ABC directory won't even exist in GitHub's build environment—this is likely the root cause of your "No such file or directory" error.

2. Make the PRT Variable Path-agnostic

Instead of hardcoding PRT=ABC, define it using the absolute path of your Makefile's location. This ensures it always points to the correct ABC submodule, regardless of where the project is checked out.

Modify your XYZ project's Makefile like this:

# Get the absolute path of the directory containing this Makefile
MAKEFILE_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

# Set PRT to the absolute path of the ABC submodule, unless explicitly overridden
ifndef PRT
PRT := $(MAKEFILE_DIR)/ABC
export PRT
endif

# Rest of your Makefile content remains unchanged...
.PHONY: project_ project_clean project_check clean XYZ_package package check
project_ project_clean project_check:
	@echo "(MAKE) -C src -s $(@:project_%=%)"
	@$(MAKE) -C src -s $(@:project_%=%)
clean: project_clean
XYZ_package package: ./scripts/package.sh
check: project_check

3. Verify Your src Directory's Makefile Uses PRT Correctly

Double-check that the Makefile inside your src directory uses the $(PRT) variable instead of hardcoding ABC for include paths or library references. For example, if you have a line like:

INCLUDES += -IABC/include

Change it to:

INCLUDES += -I$(PRT)/include

Why Did This Work Locally But Fail on GitHub?

Locally, you already ran git submodule add and initialized the ABC submodule, so the directory exists. GitHub Actions, however, doesn't do this by default. Additionally, GitHub's checkout process might use a slightly different directory name (like XYZ @ 324354), which breaks hardcoded relative paths—using the absolute path derived from the Makefile fixes this.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 10:01:16