分步说明如何使用Msys2为Mingw安装Rust和Cargo? [英] Step by step instruction to install Rust and Cargo for mingw with Msys2?

查看:808
本文介绍了分步说明如何使用Msys2为Mingw安装Rust和Cargo?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Cygwin上安装Rust,但是无法与mingw链接.现在,我尝试使用Msys2进行安装.我已经安装了Msys2和Mingw.我试图遵循此Wiki页面但我迷路于第二名:

I tried to install Rust on Cygwin but failed to be able link with mingw. Now I am trying to install it with Msys2. I already installed Msys2 and Mingw. I tried to follow this wiki page but I got lost at number 2:

使用安装程序下载并安装Rust + Cargo,但请确保禁用链接器和平台库"选项.

Download and install Rust+Cargo using the installer but be sure to disable the Linker and platform libraries option.

是指安装页面上的"rustup-init.exe" ?我应该双击运行该文件还是从Msys2运行它?我尝试从Msys2运行并获得了以下选项:

Is it referring to the "rustup-init.exe" on the install page? Should I double click to run this file or run it from Msys2? I tried to run from Msys2 and got the options:

1) Proceed with installation (default)  
2) Customize installation  
3) Cancel installation

我不知道下一步该怎么做.

I don't know what to do next.

我试图遵循弗朗西斯的回答:

I tried to follow Francis' answer:

Thang@Thang-Laptop MINGW64 /c/Software/Rust
$ ./rustup-init.exe

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 2015 which provides just the Visual C++ build tools:

  http://landinghub.visualstudio.com/visual-cpp-build-tools

Alternately, you can install Visual Studio 2015 or Visual Studio 2013 and
during install select the "C++ tools":

  https://www.visualstudio.com/downloads/

Install the C++ build tools before proceeding.

If you will be targetting 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) Y


Welcome to Rust!

This will download and install the official compiler for the Rust programming
language, and its package manager, Cargo.

It will add the cargo, rustc, rustup and other commands to Cargo's bin
directory, located at:

  C:\Users\Thang\.cargo\bin

This path will then be added to your PATH environment variable by modifying the
HKEY_CURRENT_USER/Environment/PATH registry key.

You can uninstall at any time with rustup self uninstall and these changes will
be reverted.

Current installation options:

   default host triple: x86_64-pc-windows-msvc
     default toolchain: stable
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
2

I'm going to ask you the value of each these installation options.
You may simply press the Enter key to leave unchanged.

Default host triple?
x86_64-pc-windows-gnu

Default toolchain? (stable/beta/nightly/none)
stable

Modify PATH variable? (y/n)
y


Current installation options:

   default host triple: x86_64-pc-windows-gnu
     default toolchain: stable
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
1

info: updating existing rustup installation


Rust is installed now. Great!

To get started you need Cargo's bin directory (%USERPROFILE%\.cargo\bin) in
your PATH environment variable. Future applications will automatically have the
correct environment, but you may need to restart your current shell.

Press the Enter key to continue.


Thang@Thang-Laptop MINGW64 /c/Software/Rust
$ rustc --version
bash: rustc: command not found

我添加了配置文件.不知道我是否想念

I added the config file. Not sure if I miss anything

Thang@Thang-Laptop MINGW64 /c/Users/Thang/.cargo
$ cat config
[target.x86_64-pc-windows-gnu]
linker = "C:\msys2\mingw64\bin\gcc.exe"
ar = "C:\msys2\mingw64\bin\ar.exe"
Thang@Thang-Laptop MINGW64 /c/Users/Thang/.cargo
$ cargo --version
bash: cargo: command not found


我刚刚重新启动了笔记本电脑.仍然无法使用,我检查了msys2中的路径,没有货运文件夹

Edit 2:
I have just restarted my laptop. It's still not work, I check the Path in msys2, there is no cargo folder

Thang@Thang-Laptop MINGW64 ~
$ echo $PATH
/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/c/Windows/System32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/

但是我在环境变量的用户变量中看到了它.

but I saw it in user variables in Environment Variables.

Thang@Thang-Laptop MINGW64 /c/Users/Thang/.cargo/bin
$ ./rustup default stable-x86_64-pc-windows-gnu
info: syncing channel updates for 'stable-x86_64-pc-windows-gnu'
info: latest update on 2017-10-12, rust version 1.21.0 (3b72af97e 2017-10-09)
info: downloading component 'rustc'
info: downloading component 'rust-std'
info: downloading component 'cargo'
info: downloading component 'rust-docs'
info: downloading component 'rust-mingw'
info: installing component 'rustc'
info: installing component 'rust-std'
info: installing component 'cargo'
info: installing component 'rust-docs'
info: installing component 'rust-mingw'
info: default toolchain set to 'stable-x86_64-pc-windows-gnu'

  stable-x86_64-pc-windows-gnu installed - rustc 1.21.0 (3b72af97e 2017-10-09)


Thang@Thang-Laptop MINGW64 /c/Users/Thang/.cargo/bin
$ ls
cargo.exe  rustc.exe    rust-gdb.exe   rustup.exe
rls.exe    rustdoc.exe  rust-lldb.exe

Thang@Thang-Laptop MINGW64 /c/Users/Thang/.cargo/bin
$ rustc --version
bash: rustc: command not found

推荐答案

您链接到日期的在Windows上使用Rust 页面的日期为rustup取代安装程序之前的默认选项,以安装Rust. 安装程序仍然可用,但是您应该使用如果可能的话,进行rustup,因为它使更新和一次使用多个工具链(例如稳定版,beta版和夜间版)变得容易.如果必须使用安装程序,只需选择x86_64-pc-windows-gnu安装程序,然后按照在Windows上使用Rust 页中的步骤进行操作.如果您正在使用rustup,请继续阅读.

The Using Rust on Windows page you linked to dates from before rustup replaced the installer as the default option to install Rust. Installers are still available, but you should use rustup if possible, because it makes it easy to update and to use multiple toolchains at once (e.g. stable, beta and nightly). If you must use the installer, just select the x86_64-pc-windows-gnu installer and follow the step from the Using Rust on Windows page. If you're using rustup, read on.

默认情况下,Windows上的rust安装针对MSVC工具链而不是GNU/MinGW-w64工具链的编译器和工具.在初始菜单中,选择 2)自定义安装.当要求输入主机三元组时,输入x86_64-pc-windows-gnu.然后选择其他问题,然后继续安装.

By default, rustup on Windows installs the compiler and tools targeting the MSVC toolchain, rather than the GNU/MinGW-w64 toolchain. At the initial menu, select 2) Customize installation. When asked for a host triple, enter x86_64-pc-windows-gnu. Then make a choice for the other questions, then proceed with the installation.

注意::如果已经安装了rustup,则重新运行rustup-init实际上不会安装请求的工具链.相反,如果您已经具有基于MSVC的工具链,请运行rustup toolchain install stable-x86_64-pc-windows-gnu.然后运行rustup default stable-x86_64-pc-windows-gnu将基于GNU的工具链设置为默认.

Note: If rustup is already installed, then rerunning rustup-init won't actually install the requested toolchain. Instead, run rustup toolchain install stable-x86_64-pc-windows-gnu if you already have the MSVC-based toolchain. Then run rustup default stable-x86_64-pc-windows-gnu to set the GNU-based toolchain as the default.

Rustup将自动安装MinGW链接器和平台库(作为rust-mingw组件的一部分),并拒绝您删除它们.如果您喜欢使用随MSYS2安装的MinGW链接器和库,则需要创建 .cargo/config 文件(位于您的配置文件目录(即C:\Users\you\.cargo\config中),或者位于此项目的目录中(如果此配置特定于项目).该文件的内容可能如下所示:

Rustup will install the MinGW linker and platform libraries automatically (as part of the rust-mingw component) and refuses to let you remove them. If you prefer to use the MinGW linker and libraries you installed with MSYS2, you'll need to create a .cargo/config file (either in your profile directory, i.e. C:\Users\you\.cargo\config, or in your project's directory if this configuration is specific to a project). The contents of that file might look like this:

[target.x86_64-pc-windows-gnu]
linker = "C:\\msys2\\mingw64\\bin\\gcc.exe"
ar = "C:\\msys2\\mingw64\\bin\\ar.exe"

Rustup会修改PATH环境变量,除非您告知您不要这样做.但是,MSYS2在启动时默认情况下会重置PATH,因此,当您尝试从MSYS2 shell调用cargorustc时,可能找不到它.您需要编辑.profile/.bash_profile脚本以正确设置PATH(您需要在/c/Users/yourname/.cargo/bin:之前添加到PATH).

Rustup will modify the PATH environment variable unless you told it not to. However, MSYS2 resets PATH by default when you launch, so when you try to invoke cargo or rustc from your MSYS2 shell, it might not find it. You'll need to edit your .profile/.bash_profile script to set the PATH correctly (you need to prepend /c/Users/yourname/.cargo/bin: to PATH).

这篇关于分步说明如何使用Msys2为Mingw安装Rust和Cargo?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆