window下rust的安装

window下rust的安装_第1张图片
window下rust的安装_第2张图片
window下rust的安装_第3张图片

删除rustup重装
window下rust的安装_第4张图片
window下rust的安装_第5张图片

环境变量配置:
通过RUST_HOME指定rustup的安装目录。
通过CARGO_HOME指定cargo的安装过目录。

window下rust的安装_第6张图片
window下rust的安装_第7张图片

再次运行rustup-init文件
window下rust的安装_第8张图片

观察到安装界面的rustup路径和和cargo已经发生改变;
重复之前的步骤安装即可;

最后检查是否安装成功了;
window下rust的安装_第9张图片

运行:
$ rustc --version
window下rust的安装_第10张图片

明显是ok的;

中文非官方的翻译文档(入坑教程文档):
https://kaisery.github.io/trpl-zh-cn/foreword.html

安装官网的示例教程,新建一个demo
window下rust的安装_第11张图片

window下rust的安装_第12张图片

Cargo run的时候报错了;
window下rust的安装_第13张图片

由于不做c#开发,而且安装vs开发工具太大了,磁盘空间紧张所以用一下方法会更好:
参考:https://www.jianshu.com/p/718626d561ce

rustup uninstall toolchain stable-x86_64-pc-windows-msvc
rustup toolchain install stable-x86_64-pc-windows-gnu (or download rustup-init for the platform of your choice at https://forge.rust-lang.org/infra/other-installation-methods.html)
rustup default stable-x86_64-pc-windows-gnu

window下rust的安装_第14张图片

用vscode打开的话只要安装几个插件就可以运行编译rust了
window下rust的安装_第15张图片

从网上下载项目构建后,发生了错误;百度后还是觉得要重新安装好vc++才行,避免后面又遇到一些坑;
PS H:\git_workplace\rust_project\rust-admin> cargo build
Blocking waiting for file lock on build directory
Compiling brotli-sys v0.3.2
Compiling ring v0.16.20
Compiling sys-info v0.5.10
Compiling libz-sys v1.1.3
error: failed to run custom build command for libz-sys v1.1.3

Caused by:
process didn’t exit successfully: H:\git_workplace\rust_project\rust-admin\target\debug\build\libz-sys-db023d3423358cf0\build-script-build (exit code: 1)
— stdout
cargo:rerun-if-env-changed=LIBZ_SYS_STATIC
cargo:rerun-if-changed=build.rs
cargo:rerun-if-env-changed=ZLIB_NO_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-pc-windows-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_pc_windows_gnu
cargo:rerun-if-env-changed=HOST_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG
cargo:rerun-if-env-changed=ZLIB_STATIC
cargo:rerun-if-env-changed=ZLIB_DYNAMIC
cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-pc-windows-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_pc_windows_gnu
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-pc-windows-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_pc_windows_gnu
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-pc-windows-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_pc_windows_gnu
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
TARGET = Some(“x86_64-pc-windows-gnu”)
OPT_LEVEL = Some(“0”)
HOST = Some(“x86_64-pc-windows-gnu”)
CC_x86_64-pc-windows-gnu = None
CC_x86_64_pc_windows_gnu = None
HOST_CC = None
CC = None
CFLAGS_x86_64-pc-windows-gnu = None
CFLAGS_x86_64_pc_windows_gnu = None
HOST_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some(“true”)
CARGO_CFG_TARGET_FEATURE = Some(“fxsr,sse,sse2”)
running: “gcc.exe” “-O0” “-ffunction-sections” “-fdata-sections” “-g” “-fno-omit-frame-pointer” “-m64” “-I” “src/zlib” “-o” “H:\git_workplace\rust_project\rust-admin\target\debug\build\libz-sys-03a2e7e80ae574b3\out\lib\src/zlib/adler32.o” “-c” “src/zlib/adler32.c”

— stderr

error occurred: Failed to find tool. Is gcc.exe installed? (see https://github.com/alexcrichton/cc-rs#compile-time-requirements for help)

warning: build failed, waiting for other jobs to finish…
error: build failed
PS H:\git_workplace\rust_project\rust-admin> cargo build
Compiling brotli-sys v0.3.2
Compiling ring v0.16.20
Compiling sys-info v0.5.10
Compiling libz-sys v1.1.3

Caused by:
process didn’t exit successfully: H:\git_workplace\rust_project\rust-admin\target\debug\build\sys-info-f54d19f21e3416a6\build-script-build (exit code: 1)
— stdout
cargo:rustc-flags=-l psapi
TARGET = Some(“x86_64-pc-windows-gnu”)
OPT_LEVEL = Some(“0”)
HOST = Some(“x86_64-pc-windows-gnu”)
CC_x86_64-pc-windows-gnu = None
CC_x86_64_pc_windows_gnu = None
HOST_CC = None
CC = None
CFLAGS_x86_64-pc-windows-gnu = None
CFLAGS_x86_64_pc_windows_gnu = None
HOST_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some(“true”)
CARGO_CFG_TARGET_FEATURE = Some(“fxsr,sse,sse2”)
running: “gcc.exe” “-O0” “-ffunction-sections” “-fdata-sections” “-g” “-fno-omit-frame-pointer” “-m64” “-Wall” “-Wextra” “-o” “H:\git_workplace\rust_project\rust-admin\target\debug\build\sys-info-0414f7f9920be724\out\c/windows.o” “-c” “c/windows.c”

— stderr

error occurred: Failed to find tool. Is gcc.exe installed? (see https://github.com/alexcrichton/cc-rs#compile-time-requirements for help)

warning: build failed, waiting for other jobs to finish…
error: build failed

window下rust的安装_第16张图片

索性从新下载,最后还是选择下载vs2022

window下rust的安装_第17张图片

window下rust的安装_第18张图片
window下rust的安装_第19张图片
window下rust的安装_第20张图片

Cmd重新安装
rustup toolchain install stable-x86_64-pc-windows-msvc

rustup default stable-x86_64-pc-windows-msvc

Ps:当遇到编译问题编译不过时排查:
1网络问题(是当前网络不佳,还是资源依赖不存在了;也可尝试切换替国内的换镜像源)。2工具链问题(可以尝试切换工具链再重新编译一波)

你可能感兴趣的:(笔记,编程语言,rust,rust,开发语言,后端)