MSVC必须文件
要将程序编译成exe
文件,Rust需要链接器、库和 Windows API 导入库,可以通过安装Visual Studio来安装以上组件。
自动安装
如果您没有安装Visual Studio,则 rustup-init 将提供自动安装MSVC必须组件。 这样做意味着您可以跳过本页的其余部分。 但是,它安装的Visual Studio社区版本可能并不适合所有用户。 它对个人、学术研究和开源使用是免费的,但不适用于其他用途,例如专有企业软件。 用户应询问他们的组织哪个版本适合他们。 有关更多详细信息,请参阅 许可条款 。
常规安装
下载Visual Studio. Rust supports Visual Studio 2017 and later but it is recommended that you use the latest version (currently 2022) for new projects. You can opt to download only the Build Tools for Visual Studio, which does not include the IDE. However this requires you already have a license to the Community, Professional or Enterprise edition.
Once you’ve downloaded and started the installer, the easiest way to get everything installed is to select “Desktop Development with C++”. This will include the necessary components. On the “Language Packs” tab, make sure the English language pack is installed in addition to your preferred language.
If you want more details on the installation process or want to further customize the install then follow the walkthrough below. Otherwise complete the Visual Studio install and continue with installing Rust.
Walkthrough: Installing Visual Studio 2022
This walkthrough uses the Community edition of Visual Studio but the Professional, Enterprise and the Build Tools all work the same way.
The installer will start by linking to the [license][vs licences] and for your edition of Visual Studio and then preparing the installer.
Once this finishes, you can then select the components to be installed.
Here we use the “Workload” tab to select the “Desktop Development with C++” workload.
This will includes all needed components for Rust:
安装必须组件 (可选)
If you’d like a more minimal install (and won’t be doing C++ development) then you can use the “Individual Components” tab to select just the essentials, which are:
- MSVC v143 - VS 2022 C++ x64/x86 build tools (最新)
- Windows 11 SDK (10.0.22621.0)
Note that the specific version of the Windows SDK doesn’t matter for pure Rust code but if using C++ as well you’ll likely want either the latest or whichever version is required by the C++ project (or both).
添加语言包 (可选)
After choosing the components, you may also want to select the language packs to install. Switch to the “Language Packs” tab and add the languages. It is recommended that you add the English language pack in addition to your preferred language. This will provide English language error messages, which may help when reporting errors.
完成安装
Finally click the install button and wait for everything to be installed.
Once finished, you can continue on to installing Rust.