2025-10-24 使用rust进行桌面端应用开发遇到报错(win11):error: could not compile `windows_x86_64_msvc` (build script) due to 1 previous error==》查看Visual Studio Build Tools是否安装了项目所需的C++运行环境组件
error: could not compile `windows_x86_64_msvc` (build script) due to 1 previous error
翻译:错误:由于之前的1个错误,无法编译`windows_x86_64_msvc`(构建脚本)
这个报错的大意是rust项目中缺少必要的C++构建工具。
一般可以从两方面入手排查,如果你的工具链就是msvc,那么请检查你的Visual Studio Build Tools是否安装,并且有勾选了C++ 桌面开发组件
以我的电脑安装的vs2022为例,排查一下:

点击修改,然后在【工作负载】选项卡查看

妈呀,还真没有勾选这个组件😀
行吧,那么浅浅地勾选吧,然后点右下角的修改,等这个组件下载完后,重启一下电脑,最后再运行一下项目就行了(ps:额...,我电脑咋没空间了😀)

临时方案:
如果你不用这个工具链,可以切到gnu,用gnu解决,不建议长期使用
在项目终端输入rustup show查看工具链配置信息,比如我的显示如下:
PS D:\test\rust-test\digital_clock> rustup show Default host: x86_64-pc-windows-msvc rustup home: C:\Users\纪念馆\.rustup installed toolchains -------------------- stable-x86_64-pc-windows-gnu stable-x86_64-pc-windows-msvc (active, default) active toolchain ---------------- name: stable-x86_64-pc-windows-msvc active because: it's the default toolchain installed targets: x86_64-pc-windows-msvc
注意1:如果你没有安装gnu,得先装一下,有就不用管这一步
rustup toolchain install stable-x86_64-pc-windows-gnu
注意2:把工具连默认项设置为gnu,像上面我的那个就是默认msvc的,现在我要切到gnu了,那么得输入以下命令:
rustup default stable-x86_64-pc-windows-gnu
这个命令是切换工具链默认选择项的
然后再用查看一下配置
rustup show
如下便是成功设置:
PS D:\test\rust-test\digital_clock> rustup default stable-x86_64-pc-windows-gnu info: using existing install for 'stable-x86_64-pc-windows-gnu' info: default toolchain set to 'stable-x86_64-pc-windows-gnu' stable-x86_64-pc-windows-gnu unchanged - rustc 1.90.0 (1159e78c4 2025-09-14) PS D:\test\rust-test\digital_clock> rustup show Default host: x86_64-pc-windows-msvc rustup home: C:\Users\纪念馆\.rustup installed toolchains -------------------- stable-x86_64-pc-windows-gnu (active, default) stable-x86_64-pc-windows-msvc active toolchain ---------------- name: stable-x86_64-pc-windows-gnu active because: it's the default toolchain installed targets: x86_64-pc-windows-gnu
============= 若干分钟后 =============
....恩....其实切换到gnu也没有解决我的问题,还是报错了😂

浙公网安备 33010602011771号