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

Rust依赖版本冲突:为何Cargo无法统一rusqlite版本?

问题:Cargo依赖冲突:rusqlite版本不统一导致libsqlite3-sys冲突?

我的Cargo.toml中引入了两个最新版本的依赖:

rusqlite = "0.37"
sea-query-rusqlite = "0.7"

执行cargo check时,因libsqlite3-sys原生库版本冲突报错:

Updating crates.io index
error: failed to select a version for `libsqlite3-sys`.
    ... required by package `rusqlite v0.32.0`
    ... which satisfies dependency `rusqlite = "^0.32"` of package `sea-query-rusqlite v0.7.0`
    ... which satisfies dependency `sea-query-rusqlite = "^0.7"` of package `core v0.0.0 (<local_path_here>)`
versions that meet the requirements `^0.30.0` are: 0.30.1, 0.30.0

package `libsqlite3-sys` links to the native library `sqlite3`, but it conflicts with a previous package which links to `sqlite3` as well:
package `libsqlite3-sys v0.35.0`
    ... which satisfies dependency `libsqlite3-sys = "^0.35.0"` of package `rusqlite v0.37.0`
    ... which satisfies dependency `rusqlite = "^0.37"` of package `core v0.0.0 (<local_path_here>)`
Only one package in the dependency graph may specify the same links value. This helps ensure that only one copy of a native library is linked in the final binary. Try to adjust your dependencies so that only one package uses the `links = "sqlite3"` value. For more information, see https://doc.rust-lang.org/cargo/reference/resolver.html#links.

failed to select a version for `libsqlite3-sys` which could resolve this conflict

我疑惑的是:Cargo为何同时链接rusqlite 0.32和0.37两个版本?sea-query-rusqlite依赖^0.32版本,而我依赖0.37版本,根据Rust文档,0.32与^0.32等价,为何Cargo不统一使用0.37版本来满足两者需求?


解答

  • 核心误解在于0.x版本的语义化版本规则:^0.32的版本范围是>=0.32.0 且 <0.33.0,并非兼容0.37这类更高小版本。Rust语义化版本中,0.x属于开发阶段,小版本号的升级被视为不兼容的重大变更,因此^0.m.n仅匹配同小版本的补丁更新,不会包含更高小版本(如0.33及以上)。

  • 这意味着sea-query-rusqlite v0.7.0要求的rusqlite ^0.32只能适配0.32.x系列版本,而你直接依赖的rusqlite 0.37属于完全独立的版本分支,Cargo无法用0.37满足前者的依赖要求,只能同时引入两个版本的rusqlite。

  • 两个版本的rusqlite各自依赖不同版本的libsqlite3-sys,而libsqlite3-sys通过links = "sqlite3"声明链接原生sqlite库。Cargo禁止同一个原生库被多个不同版本的包链接(避免最终二进制中出现多份原生库副本),因此触发冲突报错。

  • 可行解决方案:

    • 降级自身依赖的rusqlite到0.32.x版本,与sea-query-rusqlite的依赖范围对齐;
    • 升级sea-query-rusqlite到支持rusqlite 0.37的版本(可查看该 crate 的最新版本是否已更新依赖范围)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 16:35:17