window下rust的安装

2023-05-16

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

删除rustup重装
在这里插入图片描述
在这里插入图片描述

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

在这里插入图片描述
在这里插入图片描述

再次运行rustup-init文件
在这里插入图片描述

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

最后检查是否安装成功了;
在这里插入图片描述

运行:
$ rustc --version
在这里插入图片描述

明显是ok的;

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

安装官网的示例教程,新建一个demo
在这里插入图片描述

在这里插入图片描述

Cargo run的时候报错了;
在这里插入图片描述

由于不做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

在这里插入图片描述

用vscode打开的话只要安装几个插件就可以运行编译rust了
在这里插入图片描述

从网上下载项目构建后,发生了错误;百度后还是觉得要重新安装好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

在这里插入图片描述

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

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

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

rustup default stable-x86_64-pc-windows-msvc

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

window下rust的安装 的相关文章

随机推荐