惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
DataBreaches.Net
N
Netflix TechBlog - Medium
P
Proofpoint News Feed
D
Docker
J
Java Code Geeks
L
LangChain Blog
Microsoft Security Blog
Microsoft Security Blog
The GitHub Blog
The GitHub Blog
I
InfoQ
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
Engineering at Meta
Engineering at Meta
MongoDB | Blog
MongoDB | Blog
月光博客
月光博客
T
Tailwind CSS Blog
M
MIT News - Artificial intelligence
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
腾讯CDC
罗磊的独立博客
U
Unit 42
爱范儿
爱范儿
Vercel News
Vercel News
MyScale Blog
MyScale Blog

树 - 洞

SMTP2GO 拯救你的 25 端口限制 | 树 SMTP2GO 拯救你的 25 端口限制 | 树 Bilibili Linux 客户端 VAAPI 硬解折腾全记录 | 树 Bilibili Linux 客户端 VAAPI 硬解折腾全记录 | 树 震惊!insmtr 的 MySQL 数据库居然被勒索软件攻击了! | 树 震惊!insmtr 的 MySQL 数据库居然被勒索软件攻击了! | 树 再探阿里云 DNS 对 CloudFront 的解析情况 | 树 再探阿里云 DNS 对 CloudFront 的解析情况 | 树 为单板机配置超简单 VNC 环境 改良版 | 树 为单板机配置超简单 VNC 环境 改良版 | 树 Ubuntu 22.04 Rust OpenCV 注意事项 | 树 Redmi AX6000 hanwckf U-Boot 安装 OpenWrt 24 | 树 为单板机配置超简单 VNC 环境 | 树 Redmi AX6000 hanwckf U-Boot 安装 OpenWrt 24 | 树 为单板机配置超简单 VNC 环境 | 树 在 WSL 中使用 ISE | 树 在 WSL 中使用 ISE | 树 Jetson AGX Orin CH340 驱动安装 | 树 Jetson AGX Orin CH340 驱动安装 | 树 在 Ubuntu 22.04 上运行 PX4-Autopilot 1.13 | 树 在 Ubuntu 22.04 上运行 PX4-Autopilot 1.13 | 树 在 Thunderbird 里使用沉浸式翻译插件 | 树 在 Thunderbird 里使用沉浸式翻译插件 | 树 搭建自定义域名邮箱 | 树 - 洞 搭建自定义域名邮箱 | 树 - 洞 Android Box for root 透明代理 | 树 再见,曾经热爱的算法竞赛 | 树 - 洞 再见,曾经热爱的算法竞赛 | 树 - 洞
Ubuntu 22.04 Rust OpenCV 注意事项 | 树
insmtr · 2025-05-13 · via 树 - 洞

最近在使用 Rust 语言开发的时候需要用到 OpenCV 库,结果配置的时候遇到了一些问题,便记录一下。

安装

Rust 的 OpenCV 库依赖了 Clang 作为编译器,所以使用前需要先安装 Clang :

sudo apt update
sudo apt install -y libopencv-dev clang libclang-dev

然后在项目的 Cargo.toml 中添加依赖:

[dependencies]
opencv = { version = "*", features = ["clang-runtime"] }

处理链接库问题

如果就这样的话,我们在编译的时候会得到这样的报错:

fatal error: 'memory' file not found

这是因为 Clang 在编译的时候没有把 C++ 的头文件路径添加到编译器的搜索路径中。我们可以通过设置环境变量 CPLUS_INCLUDE_PATH 来解决这个问题。在 ~/.bashrc 中添加以下内容:

export CPLUS_INCLUDE_PATH=/usr/include/c++/11:/usr/include/x86_64-linux-gnu/c++/11

当然,在 aarch64 的系统上就需要添加:

export CPLUS_INCLUDE_PATH=/usr/include/c++/11:/usr/include/aarch64-linux-gnu/c++/11

这样就可以正常编译了。

但是 VSCode 中的 Rust LSP 依然会报错,提示找不到头文件。我们可以通过在 settings.json 中添加以下内容来解决这个问题:

{
    "rust-analyzer.server.extraEnv": {
        "CPLUS_INCLUDE_PATH": "${env:CPLUS_INCLUDE_PATH}:/usr/include/c++/11:/usr/include/${arch}/c++/11"
    }
}

然后就完全正常了。

结语

以上就是在 Ubuntu 22.04 上使用 Rust 调用 OpenCV 库时需要注意的一些细节。希望对你有所帮助。