不灭的焱

革命尚未成功,同志仍须努力 下载Java21

作者:AlbertWen  添加时间:2026-07-20 19:07:16  修改时间:2026-07-26 23:29:57  分类:01.Rust编程  编辑

目录

这个错误表示:

Rust 编译过程中需要调用 GNU 工具链中的 dlltool.exe,但系统在 PATH 环境变量中找不到该程序。

error: error calling dlltool 'dlltool.exe': program not found

parking_lot_core 只是编译失败时显示出来的依赖库,通常不是 parking_lot_core 本身有问题,根本原因是 Windows 编译工具链不完整。

一、先检查当前 Rust 工具链

在 PowerShell 中执行:

rustup show

再执行:

rustc -vV

重点查看这一行:

host: x86_64-pc-windows-gnu

或者:

host: x86_64-pc-windows-msvc

如果显示:

x86_64-pc-windows-gnu

就说明当前项目使用的是 GNU 工具链,它需要 MinGW、GCC、Binutils 等外部工具,其中就包括 dlltool.exe

解决方案:切换到 MSVC 工具链

对于普通 Windows Rust 开发,建议使用:

x86_64-pc-windows-msvc

Rust 官方也建议大多数 Windows 用户优先使用 MSVC ABI,因为它与 Windows 和 Visual Studio 生态兼容性更好。(rust-lang.github.io)

1. 安装 MSVC 版 Rust 工具链

rustup toolchain install stable-msvc

设置为默认工具链:

rustup default stable-msvc

确认:

rustc -vV

应该看到:

host: x86_64-pc-windows-msvc

2. 安装 Visual Studio C++ 编译环境

MSVC 版 Rust 仍然需要 Windows 链接器和 SDK。

安装 Visual Studio 2022 Build Tools,并选中:

详细安装教程 请查看:Windows安装Rust 

使用 C++ 的桌面开发

至少需要以下组件:

MSVC v143 C++ x64/x86 build tools
Windows 10 SDK 或 Windows 11 SDK

Rust 官方说明,MSVC 目标需要 Visual Studio 提供链接器、运行库以及 Windows SDK。(rust-lang.github.io)

3. 清理后重新编译

进入项目目录:

cargo clean
cargo build

或者:

cargo run

如果切换后仍然显示 GNU

项目可能单独设置了工具链,覆盖了全局配置。

检查项目级工具链

执行:

rustup show
rustup override list

如果当前项目存在 GNU override,可以在项目目录执行:

rustup override unset

然后设置当前项目使用 MSVC:

rustup override set stable-msvc

再次检查:

rustup show active-toolchain

应该类似:

stable-x86_64-pc-windows-msvc

项目目录中还可能存在:

rust-toolchain
rust-toolchain.toml

例如内容是:

[toolchain]
channel = "stable-gnu"

可以改成:

[toolchain]
channel = "stable-msvc"

Rustup 的项目级 override 和 rust-toolchain.toml 会覆盖全局默认工具链。(rust-lang.github.io)

检查 Cargo 是否强制指定 GNU 目标

查看项目中的:

.cargo/config.toml

或者:

.cargo/config

如果存在:

[build]
target = "x86_64-pc-windows-gnu"

将其删除,或者改成:

[build]
target = "x86_64-pc-windows-msvc"

然后执行:

cargo clean
cargo build