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

构建opencv-rust时cargo build进程卡住求助

解决opencv-rust构建卡住的问题

先确认进程状态

别直接重启,打开新终端运行htop,查看是否有cmake或make相关进程在占用CPU/内存。如果有持续资源消耗,说明还在构建(最后几步可能涉及大模块编译,耗时久属正常);如果资源占用为0,那就是进程真的挂起了。

清理缓存重新构建

  • 执行cargo clean清除Cargo缓存
  • 删除项目根目录下的target文件夹,以及~/.cargo/registry/src/*中所有带opencv的目录
  • 用cargo build -vv重新启动构建,-vv会输出详细日志,能定位具体卡住的步骤

调整文件描述符限制

Ubuntu默认的文件描述符上限不足,可能导致构建停滞:

  • 临时提升限制:在终端执行ulimit -n 65536,再重新运行cargo build
  • 永久修改:编辑/etc/security/limits.conf,添加以下内容后重启系统:
    * soft nofile 65536
    * hard nofile 65536
    

替换OpenCV安装源

系统自带的libopencv-dev可能存在功能缺失,换用官方PPA的包:

  • 卸载现有包:sudo apt remove libopencv-dev
  • 添加官方PPA:sudo add-apt-repository ppa:opencv/opencv-4.x
  • 更新并重装:sudo apt update && sudo apt install libopencv-dev
  • 重新执行cargo build

降级opencv-rust版本

0.83.0版本可能与你的环境存在兼容性问题,尝试稳定旧版本:

  • 修改Cargo.toml中的依赖配置:
    opencv = "0.80.0"
    
  • 执行cargo update更新依赖,再重新构建

对齐Clang与LLVM版本

你的Rust使用LLVM 16.0.5,需确保Clang版本匹配:

  • 查看当前Clang版本:clang --version
  • 若版本不匹配,安装对应版本的Clang:
    sudo apt install clang-16
    sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-16 100
    sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-16 100
    
  • 重新运行cargo build

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 22:46:02