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

RISC-V GNU Toolchain子模块拉取失败:服务器拒绝未公开对象请求

RISC-V GNU Toolchain编译报错问题排查与解决

环境

  • 操作系统:Ubuntu20.04LTS

问题描述

按照riscv-gnu-toolchain官方README操作,步骤如下:

  1. 克隆仓库:
git clone https://github.com/riscv/riscv-gnu-toolchain
  1. 安装依赖:
sudo apt-get install autoconf automake autotools-dev curl python3 python3-pip libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev ninja-build git cmake libglib2.0-dev libslirp-dev
  1. 配置并编译:
./configure --prefix=/opt/riscv
make

执行make后报错:

make
cd /home/fufu/gits/riscv-gnu-toolchain && \
flock `git rev-parse --git-dir`/config git submodule init /home/fufu/gits/riscv-gnu-toolchain/newlib/ && \
flock `git rev-parse --git-dir`/config git submodule update --progress --depth 1 /home/fufu/gits/riscv-gnu-toolchain/newlib/
Submodule 'newlib' (https://sourceware.org/git/newlib-cygwin.git) registered for path 'newlib'
Cloning into '/home/fufu/gits/riscv-gnu-toolchain/newlib'...
remote: Enumerating objects: 6971, done.        
remote: Counting objects: 100% (6971/6971), done.        
remote: Compressing objects: 100% (5327/5327), done.        
remote: Total 6971 (delta 2582), reused 3275 (delta 1516), pack-reused 0        
Receiving objects: 100% (6971/6971), 14.31 MiB | 3.46 MiB/s, done.
Resolving deltas: 100% (2582/2582), done.
remote: Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
error: Server does not allow request for unadvertised object 26f7004bf73c421c3fd5e5a6ccf470d05337b435
Fetched in submodule path 'newlib', but it did not contain 26f7004bf73c421c3fd5e5a6ccf470d05337b435. Direct fetching of that commit failed.
make: *** [Makefile:348: /home/fufu/gits/riscv-gnu-toolchain/newlib/.git] Error 1

已尝试操作

  • 进入newlib目录执行:
cd newlib
git checkout master
git pull origin master
git submodule update --init --recursive

报错变为:

Cloning into '/home/fufu/gits/riscv-gnu-toolchain/spike'...
Cloning into '/home/fufu/gits/riscv-gnu-toolchain/uclibc-ng'...
error: Server does not allow request for unadvertised object beb2cdbcda911764b2bed5e57921fe90493260bd
Fetched in submodule path 'binutils', but it did not contain beb2cdbcda911764b2bed5e57921fe90493260bd. Direct fetching of that commit failed.
  • 在binutils目录重复上述操作,错误依旧
  • 执行以下命令,问题仍未解决:
git submodule sync 
git submodule update --init --recursive

疑问

  1. "Server does not allow request for unadvertised object"错误的原因是什么?
  2. 如何解决该问题?

问题解答

1. 错误原因

这个错误的核心原因有两点:

  • 主仓库riscv-gnu-toolchain所引用的子模块(如newlib、binutils)的特定提交ID,在对应的子模块远程仓库中不存在或未被公开——可能是该提交被仓库作者删除、历史重写,或是主仓库引用了子模块的私有/未推送提交。
  • 默认克隆主仓库时是浅层拉取,加上make命令中用--depth 1拉取子模块,导致无法获取到指定的历史提交记录。

2. 解决方法

按优先级尝试以下方案:

方案一:重新完整克隆仓库并编译

浅层克隆会丢失大量历史信息,直接拉取完整仓库:

# 删除原有仓库
rm -rf riscv-gnu-toolchain
# 完整克隆并递归拉取子模块
git clone --recursive https://github.com/riscv/riscv-gnu-toolchain
cd riscv-gnu-toolchain
# 重新配置并编译
./configure --prefix=/opt/riscv
make

方案二:修复现有仓库的子模块引用

如果不想重新克隆,尝试更新主仓库并重置子模块:

cd riscv-gnu-toolchain
# 更新主仓库到最新版本
git pull origin master
# 同步所有子模块的远程地址
git submodule sync --recursive
# 强制重置子模块到主仓库指定的版本
git submodule update --init --recursive --force

方案三:手动切换子模块到公开分支

如果上述方法无效,可临时将子模块切换到公开分支(如master/main)再编译:

# 以newlib为例,切换到master分支并更新
cd riscv-gnu-toolchain/newlib
git checkout master
git pull origin master
# 回到主仓库重新执行编译
cd ..
make

注意:此方法可能导致主仓库与子模块版本不匹配,引发其他编译问题,仅作为临时应急方案。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 02:57:12