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

Ubuntu 22.04编译grip模块报错cannot find ‘ld’

编译grip模块报collect2: fatal error: cannot find ‘ld’问题排查

问题背景

  • 编译环境:Ubuntu 22.04
  • 编译目标:开源模块grip
  • 已预装依赖:
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install -y gcc-multilib g++-multilib
sudo apt-get install -y build-essential
sudo apt-get install -y libc6-dev libc6-dev-i386
sudo apt-get install -y cmake
  • 已完成基础排查:
    • 执行which ld返回结果为/usr/bin/ld,系统默认ld链接器存在
    • 检查$PATH环境变量,已包含/usr/bin路径,无路径配置错误

报错信息

执行make编译时,在链接生成grip_amxx_i386.so阶段失败,核心报错日志:

[ 50%] Linking CXX shared library grip_amxx_i386.so
/usr/bin/cmake -E cmake_link_script CMakeFiles/grip.dir/link.txt --verbose=1
/usr/bin/c++ -fPIC  -Wall -Wextra -Wzero-as-null-pointer-constant -Wunknown-pragmas -m32 -O3 -mtune=generic -fvisibility=hidden -flto -fPIC -static-libgcc -static-libstdc++ -Wl,--gc-sections -Wl,--version-script=/home/ubuntu/grip/version_script.lds -fuse-ld=lld -shared -Wl,-soname,grip_amxx_i386.so -o grip_amxx_i386.so CMakeFiles/grip.dir/cpp/main.cpp.o CMakeFiles/grip.dir/third_party/amxmodx/public/sdk/amxxmodule.cpp.o  rust/i686-unknown-linux-gnu/debug/libgrip_rust.a -lpthread
collect2: fatal error: cannot find ‘ld’
compilation terminated.
make[2]: *** [CMakeFiles/grip.dir/build.make:117: grip_amxx_i386.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:103: CMakeFiles/grip.dir/all] Error 2
make: *** [Makefile:94: all] Error 2

根因分析

从链接命令的参数可以看到,编译配置里显式加了-fuse-ld=lld,要求使用LLVM项目的lld作为链接器,但当前系统没有安装lld。gcc自带的collect2链接封装工具在按参数查找lld失败时,没有正确回退到系统默认的GNU ld,直接抛出找不到ld的误导性报错,加上本次编译带-m32参数生成32位共享库,进一步触发了这个查找逻辑的异常。

修复方法

  1. 安装缺失的lld链接器:
sudo apt update
sudo apt install -y lld
  1. 清理历史编译缓存后重新构建:
make clean
make

如果上述操作后仍存在链接错误,补充安装32位架构对应的lld组件即可:

sudo apt install -y lld:i386

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.28 22:27:32