本文已参与「新人创作礼」活动,一起开启掘金创作之路。
1. 安装前环境准备
Rust只有编译器没有链接器,还需要C/C++的链接器。Windows上C/C++的编译链有微软提供的Visual Studio的 MSVC和GNU的MinGW
为什么Windows下安装Rust需要C/C++的链接器,应该是需要支持FFI 的原因
由于我的电脑已经安装VS2017,所以无需再安装
没有链接器环境的下载访问:visualstudio.microsoft.com/zh-hans/vis…
下载安装
2. 安装
2.1 下载
下载首页:www.rust-lang.org/zh-CN/tools…
下载路径:static.rust-lang.org/rustup/dist…
当然,我这里选择下载的是32位的安装程序
2.2 安装
双击运行下载的exe,如下界面
2.3 安装完成
3.验证
以管理员身份重新打开命令行
输入命令
rustc --version
4.Hello World
4.1 新建项目
新建个文件夹,命名为hello_world,然后新建 hello_world.txt文件,在hello_world.txt 里编写代码,保存,最后更改文件扩展名.txt 为 .rs
4.2 编译hello_world
在hello_world 文件夹所在路径打开powershell窗口(在hello_world 文件夹空白处 按住Shift 键,然后右键 选择 在此处打开Powershell 窗口)
输入编译命令
rustc .\hello_world.rs
4.3 运行hello_world
输入命令
.\hello_world.exe