13
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

RustでHello world

Last updated at Posted at 2016-07-09

参考

windows

download

Visual C++ Build Toolsをインストール済みでない場合は以下を選択すること。

gnu.png

ドキュメント

コンパイル

main.rs
fn main() {
    println!("Hello, world!");
}
コンパイル
rustc main.rs
  • main.exe : 1,697,363 バイト

VC++版

error: could not exec the linker link.exe: 指定されたファイルが見つかりません。 (os error 2)

というエラーが出たときはvisualcppbuildtools_full.exeが別途必要

vs.png

Linux

apt install -y rustc

cargoを使ってhello world

cargo new prj1 --bin
  • .gitや.gitignoreも一緒に用意される。
    • ソースは src/main.rs

carg.png

cargo build
  • target/debug/prj1.exe

が生成される。直接exeを実行してもよいが、以下で実行できる。

cargo run

書式メモ

sprintf的な

main.rs
fn main() {
    let x: i32;
    x = 4;
    println!("The value of x is: {}", x);
}

function

main.rs
fn main() {
    print_number(5);
}

fn print_number(x: i32) {
    println!("x is: {}", x);
}
13
7
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?