Zob*_*wal 18 installation compiler-errors linker-errors build-tools rust
我已经从Rust安装页面在Windows上安装了Rust 。安装后,我尝试运行“ hello world”程序,但收到以下错误。
>cargo run
Run Code Online (Sandbox Code Playgroud)
错误
Compiling helloworld v0.1.0 (C:\Users\DELL\helloworld)
error: linker `link.exe` not found
note: The system cannot find the file specified. (os error 2)
note: the msvc targets depend on the msvc linker but `link.exe` was not found
note: please ensure that VS 2013, VS 2015 or VS 2017 was installed with the Visual C++ option
error: aborting due to previous error
error: Could not compile `helloworld`.
To learn more, run the command again with --verbose.
Run Code Online (Sandbox Code Playgroud)
代码:
fn main() {
println!("Hello, world!");
}
Run Code Online (Sandbox Code Playgroud)
Zob*_*wal 32
我下载并安装了Visual Studio 2019的构建工具。在安装过程中,我选择了C ++工具。它下载了将近5GB的数据。我在安装后重新启动计算机,并编译了代码,效果很好:
> cargo run
Compiling helloworld v0.1.0 (C:\Users\DELL\helloworld)
Finished dev [unoptimized + debuginfo] target(s) in 12.05s
Running `target\debug\helloworld.exe`
Hello, world!
Run Code Online (Sandbox Code Playgroud)
Rah*_*ali 30
好的!
这正是我所做的。转到https://visualstudio.microsoft.com/visual-cpp-build-tools/,它将下载 Visual Studio 安装程序。
以管理员身份运行它,然后确保下载了下面屏幕截图中列出的所有三个内容,版本并不重要,只需尝试获取最新版本即可。
点击安装。重新启动计算机。不客气。
oca*_*nis 25
案例 1:使用 C++ win 编译器,要修复它,您需要重新安装 VS 构建工具 C++ 从 Microsoft 网站下载 Visual Studio 2019 构建工具:https : //visualstudio.microsoft.com/thank-you-downloading-visual-studio /?sku=BuildTools&rel=16
下载后,在安装构建工具时,请确保安装所需的组件:
这将下载所需的文件。一旦一切都成功安装,重启并重新运行你的 Rust 程序,它将成功编译。
Case2:这个错误可能来自于你使用 GCC 编译、修复它(假设你已经有了 MinGW):
cmd 中的磁带:
rustup uninstall toolchain stable-x86_64-pc-windows-msvcrustup toolchain install stable-x86_64-pc-windows-gnu(或在https://forge.rust-lang.org/infra/other-installation-methods.html下载您选择的平台的 rustup-init )rustup default stable-x86_64-pc-windows-gnu
案例3:你不想下载带有构建工具的Visual Studio,只需安装带有g++ gcc开发包的MinGw,然后运行CASE 2
小智 21
我有一个类似的问题“ error: linking with link.exe failed: exit code: 1”
为了解决它,我做了
rustup toolchain install stable-x86_64-pc-windows-gnu
Run Code Online (Sandbox Code Playgroud)
然后
rustup default stable-x86_64-pc-windows-gnu
Run Code Online (Sandbox Code Playgroud)
和
cargo build
Compiling hello v0.1.0 (C:\Users\leke\dev\rust\hello)
Finished dev [unoptimized + debuginfo] target(s) in 1.66s
Run Code Online (Sandbox Code Playgroud)
Adm*_*tor 21
如果上述解决方案仍然不适合您(这是 2021 年),Rust 使用msvc和gnu编译器,因此您可以随时切换到 gnu 编译器:
$ rustup default stable-x86_64-pc-windows-gnu
Run Code Online (Sandbox Code Playgroud)
错误信息很不清楚,因为不需要安装 Visual Studio 来运行 Rust 代码。“Visual C++ 选项”究竟是什么意思?“VS 2013、VS 2015 或 VS 2017”也是错误的 - 无需安装这些特定版本的完整 Visual Studio。
要执行“cargo run”,您需要从Build Tools for Visual Studio安装C++ 构建工具。2019 版就好了。下载链接:https : //visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=BuildTools&rel=16#
重要的是不仅要在安装过程中选择默认的“包含”C++ 工具,还要选择三个“可选”的 C++ 构建工具:MSVC(...)、Windows 10 SDK、C++ CMake 工具适用于 Windows。
在 PowerShell 终端中运行:
winget install -e --id Microsoft.VisualStudio.2022.BuildTools
Run Code Online (Sandbox Code Playgroud)
然后:
| 归档时间: |
|
| 查看次数: |
5796 次 |
| 最近记录: |