zoukankan      html  css  js  c++  java
  • Rust <0>:源代码组织,Cargo 入门

    Rust 源代码组织,使用配套的 Cargo 工具,其功能强大,程序员可摆脱 C/C++ 中需要自行维护 make、cmake 之类配置的工作量。

    初始化一个项目:

    cargo new --bin hello_world

    指定 --bin 选项代表创建的是一个直接可执行的二进制项目,否则会生成一个库项目。

    执行 cargo run && cargo run --release 之后,项目目录结构如下:

    <fh@z:~/projects/hello_world>
    zsh/3 114  (git)-[master]-% tree 
    .
    ├── Cargo.lock
    ├── Cargo.toml
    ├── src
    │   └── main.rs
    └── target
        ├── debug
        │   ├── build
        │   ├── deps
        │   │   └── hello_world-f745b285e01df5ca
        │   ├── examples
        │   ├── hello_world
        │   ├── hello_world.d
        │   ├── incremental
        │   └── native
        └── release
            ├── build
            ├── deps
            │   └── hello_world-7399f171987fdf9d
            ├── examples
            ├── hello_world
            ├── hello_world.d
            ├── incremental
            └── native

    生成的二进制文件位于项目路径下的 target/debug 或 target/release 子目录中,--release 指生成编译优化版的二进制文件,类似于 C 语言开启 -O2 优化选项。

    其中 Cargo.toml 是 Cargo 用来管理项目结构的配置文件,其初始内容如下:

    <fh@z:~/projects/hello_world>
    zsh/3 116  (git)-[master]-% cat Cargo.toml 
    [package]
    name = "hello_world"
    version = "0.1.0"
    authors = ["kt <kt@kissos.org>"]
    
    [dependencies]

    ____

    注:rust 生成的最终可执行文件,都是无外部依赖的静态编译结果。

  • 相关阅读:
    js yui
    ie tbody table 兼容方法
    js json ie不支持json
    js ie 6,7,8 使用不了 firstElementChild
    js for in
    js json 单双引号互换
    html table 上移下移
    js autoComplate
    开发总结
    CentOS6.7 下安装git
  • 原文地址:https://www.cnblogs.com/hadex/p/7763047.html
Copyright © 2011-2022 走看看