HelloWorld and rusthelloworld in Rust Language

Source: Internet
Author: User

HelloWorld and rusthelloworld in Rust Language
HelloWorld of Rust Language

Reference:

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

1. What is Cargo?

Similar to maven/ant in java, automake in c, and Cargo is a rust project management tool. Use Cargo to do four things:

1) Configuration Management

2) download project Dependencies

3) Call the compiler rustc to compile and release the program.

4) In short, the development of rust's package solution

When you install rust, cargo will install it.

2. Create the first rust program HelloWorld

$ cargo new hello_world --bin


Check the directory structure:

$ cd hello_world$ tree ..├── Cargo.toml└── src    └── main.rs1 directory, 2 files


Compile and run it:

$ cargo build$ ./target/debug/hello_worldHello, world!

Or:

$ cargo run
Running 'target/debug/hello_world'

Hello, world!

Compile the release version:

$ cargo build --release
Program generated:

Target/release/hello_world

3 release to server

I compiled it on the development machine (Ubuntu14.04). Now I release it to the RHEL6 server and then run:

[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)

Apparently, the GLIBC of my RHEL6 is too old. Check it out:

[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 upgrade server GLIBC (failed) 1) download glibc (http://ftp.gnu.org/gnu/libc)

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

2) unzip and install
# 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.

It seems that the gcc version of RHEL6 is too low. You need to upgrade gcc. It's too hard to give up.

5. Directly Mount rust on RHEL6 (successful)
# 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)

Then recreate hello_world:

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

The generated target/release/hello_world can be run!

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

For more information, see

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


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.