我已经反复尝试过,但仍然不知道我哪里出了问题。 我从官网安装了Rust(版本1.44.1),我可以运行
rustc --version
并得到正确的结果。我可以创建一个新项目,但是当我运行 cargo test
或 cargo build
时,我收到错误。
Compiling hello-rust v0.1.0 (C:\Projects\rust-test\hello-rust)
error: linking with `link.exe` failed: exit code: 1
|
= note: "link.exe" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Projects\\rust-test\\hello-rust\\target\\debug\\deps\\hello_rust-3bd7255de8fc516c.2475ppgeya7982p6.rcgu.o" "C:\\Projects\\rust-test\\hello-rust\\target\\debug\\deps\\hello_rust-3bd7255de8fc516c.2k8om5gztlm4khis.rcgu.o" "C:\\Projects\\rust-test\\hello-rust\\target\\debug\\deps\\hello_rust-3bd7255de8fc516c.2npazqbfnne9a4sz.rcgu.o" "C:\\Projects\\rust-test\\hello-rust\\target\\debug\\deps\\hello_rust-3bd7255de8fc516c.31mw3i7sxv4jy5mf.rcgu.o" "C:\\Projects\\rust-test\\hello-rust\\target\\debug\\deps\\hello_rust-3bd7255de8fc516c.39lo872ze2g8kjy6.rcgu.o" "/OUT:C:\\Projects\\rust-test\\hello-rust\\target\\debug\\deps\\hello_rust-3bd7255de8fc516c.exe" "C:\\Projects\\rust-test\\hello-rust\\target\\debug\\deps\\hello_rust-3bd7255de8fc516c.3pzk8mfjqu22abeg.rcgu.o" "/OPT:REF,NOICF" "/DEBUG" "/NATVIS:C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/NATVIS:C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libstd.natvis" "/LIBPATH:C:\\Projects\\rust-test\\hello-rust\\target\\debug\\deps" "/LIBPATH:C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libtest-ce9bcda9bff89d22.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libterm-5685a6e382a0344d.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libgetopts-9672beb79727d086.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunicode_width-0b6119489f498de7.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_std-f43d3b6a5d7adb85.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-13b0a7dd239e134e.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-c6983deeb3795666.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libhashbrown-fb1f6de11ac9d69b.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_alloc-09135599e2aa779b.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libbacktrace-4aec9f98c25f9f5d.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_demangle-29671087b5d92459.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-7c5d84958fafcb64.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcfg_if-c820fe24a63d105a.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-eab51dcd5481cddb.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-da92c312ae6fecdd.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_core-693c88df9572eb34.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-b5aae910499df009.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-9a7454af4f639d0b.rlib" "kernel32.lib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "msvcrt.lib"
= note: /usr/bin/link: extra operand ‘/LIBPATH:C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib’
Try '/usr/bin/link --help' for more information.
error: aborting due to previous error
error: could not compile `hello-rust`.
To learn more, run the command again with --verbose.
我的研究发现,MSVC 设置不正确或 PATH 变量中缺少某些内容。这个错误是什么意思?我安装了 Visual Studio 2017(只是基础知识,我没有检查任何工作负载或单个组件),据我所知,这就是 MSVC (Microsoft Studio Visual C++)。我对 Rust 和低级编码不太熟悉(我是 Python/JavaScript 人员),所以我不太明白我需要在这里做什么。有人可以在这里指导我吗?
为什么 MSVC 无法安装或被 Rust 识别?什么可能导致这种情况?我该如何解决它?
我碰巧自己找到了答案,但我没有找到任何有关 Rust 的文档。我搜索了有关安装 MSVC 的较长时间,找到了此 Microsoft 页面:https://learn.microsoft.com/en-us/cpp/build/vscpp-step-0-installation?view=vs-2019
For core C and C++ support, choose the "Desktop development with C++" workload.
我修改了安装并选择了使用 C++ 工作负载的桌面开发。成功了!
当您使用
rustup-init.exe
安装 Rust 时,它应该会自动检测您是否安装了 Microsoft C++ 构建工具。如果尚未安装,它会首先向您提供有关如何安装它们的详细消息。
这就是 Windows 10 上的样子:
Rust Visual C++ prerequisites
Rust requires the Microsoft C++ build tools for Visual Studio 2013 or
later, but they don't seem to be installed.
The easiest way to acquire the build tools is by installing Microsoft
Visual C++ Build Tools 2019 which provides just the Visual C++ build
tools:
https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019
Please ensure the Windows 10 SDK and the English language pack components
are included when installing the Visual C++ Build Tools.
Alternately, you can install Visual Studio 2019, Visual Studio 2017,
Visual Studio 2015, or Visual Studio 2013 and during install select
the "C++ tools":
https://visualstudio.microsoft.com/downloads/
Install the C++ build tools before proceeding.
If you will be targeting the GNU ABI or otherwise know what you are
doing then it is fine to continue installation without the build
tools, but otherwise, install the C++ build tools before proceeding.
Continue? (Y/n)
确保您安装了 Windows SDK。它对我有用。