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

Rust项目执行及libc编译失败求助(os error 22)

Rust 构建与运行问题解决方案

1. cargo run 触发 os error 22 错误

解决步骤:

  • 确认目标可执行文件权限(虽手动运行正常,可再次验证):
    chmod +x target/debug/learning
    
  • 在无环境变量干扰的干净环境中运行:
    env -i PATH="$PATH" HOME="$HOME" cargo run
    
  • 重置rustup工具链为稳定版并更新:
    rustup default stable
    rustup update
    

2. 添加rand = "0.8.5"后libc v0.2.139构建失败

解决步骤:

  • 强制指定与当前rustc兼容的libc版本,修改Cargo.toml:
    [dependencies]
    rand = "0.8.5"
    libc = "=0.2.147"
    
  • 清理rustup缓存与项目构建文件后重新构建:
    rustup self clean
    cargo clean
    cargo build
    
  • 验证rustc本身是否正常工作,手动执行:
    rustc --version
    
    若输出异常,重新安装rustup:
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    
  • 手动指定RUSTC环境变量运行构建脚本,排查路径问题:
    RUSTC=$(which rustc) RUST_BACKTRACE=1 ./target/debug/build/libc-*/build-script-build
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 04:16:10