Rust语言之HelloWorld

Rust语言之HelloWorld

参考文档:

http://doc.crates.io/guide.html

1 什么是Cargo

相当于maven/ant之于java, automake之于c, Cargo是rust的项目管理工具。用 Cargo 做4件事情:

    1) 配置管理

    2) 下载项目依赖

    3) 调用编译器rustc编译,发布程序

    4) 总之开发rust的一揽子解决方案

当你安装了rust, cargo就随之安装了。

2 创建第一个rust程序HelloWorld

$ cargo new hello_world --bin


查看一下目录结构:

$ cd hello_world
$ tree .
.
├── Cargo.toml
└── src
    └── main.rs

1 directory, 2 files


编译一下,并运行之:

$ cargo build

$ ./target/debug/hello_world
Hello, world!

或者:

$ cargo run
Running `target/debug/hello_world`

Hello, world!

编译release版本:

$ cargo build --release
产生的程序:

target/release/hello_world

3 发布到服务器

我在开发机器上(Ubuntu14.04)上编译的,现在发布到RHEL6服务器,然后运行:

[root@vm-repo ~]# ./hello_world

./hello_world: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by ./hello_world)
./hello_world: /lib64/libc.so.6: version `GLIBC_2.18' not found (required by ./hello_world)

很显然,我的RHEL6的GLIBC太旧了。查看一下:

[root@vm-repo ~]# strings /lib64/libc.so.6 |grep GLIBC_

. ..
GLIBC_2.4
GLIBC_2.5
GLIBC_2.6
GLIBC_2.7
GLIBC_2.8
GLIBC_2.9
GLIBC_2.10
GLIBC_2.11
GLIBC_2.12

GLIBC_PRIVATE


4 升级服务器GLIBC(失败)

1) 下载glibc (http://ftp.gnu.org/gnu/libc/)

wget -c http://ftp.gnu.org/gnu/libc/glibc-2.22.tar.gz

2) 解压后安装

# tar zxf glibc-2.22.tar.gz
# cd glibc-2.22
# mkdir build
# cd build
# ../configure
# make -j4
# make install

...

checking for gawk... gawk

checking version of gawk... 3.1.7, ok
checking if gcc is sufficient to build libc... no
checking for nm... nm
configure: error:
*** These critical programs are missing or too old: as ld compiler
*** Check the INSTALL file for required versions.

看来RHEL6的gcc版本太低。需要升级gcc。太费劲,放弃。

5 直接在RHEL6上装rust (成功)

# curl -f -L https://static.rust-lang.org/rustup.sh -O
# sh rustup.sh

[root@vm-repo experiment]# rustc --version
rustc 1.2.0 (082e47636 2015-08-03)

然后重新创建hello_world:

# cargo new hello_world --bin
# cd hello_world
# cargo build --release

生成的 target/release/hello_world 可以运行!

================================================

更多内容请详细阅读

http://doc.crates.io/guide.html


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

车斗

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值