Rust语言之HelloWorld
2015-09-11 13:19
302 查看
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 runRunning `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[/code]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
相关文章推荐
- NSDateFormatter转换时间字符串时的时区问题
- #1063 : 缩地
- hdu 3635 Dragon Balls(并查集应用)
- JavaWeb——文件上传和下载
- 教你透彻了解红黑树
- ios开发者账号申请流程
- 哈希算法
- 递归罗列磁盘内容
- [LeetCode 231] Power of Two
- 分页显示的思考与实现
- Linux Shell 脚本中字符串的连接方法
- 一生必读的60部名著
- 自己看别人看了没用,UNICODE下连接数据库
- SSHconnection
- win7下cocos2dx开发环境搭建
- ACM —— 1010 STAMPS
- PHP的输出缓冲区(转)
- LDA 主题模型的几种概率分布
- IOS打开照相机与本地相册选择图片
- 《剑指offer》树的子结构