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 生成的最终可执行文件,都是无外部依赖的静态编译结果。

  • 相关阅读:
    ActiveMQ的学习(四)(消息投递方式+死信队列+重发策略)
    ActiveMQ的学习(三)(ActiveMQ的消息事务和消息的确认机制)
    ActiveMQ的学习(二)(ActiveMQ的持久化)
    ActiveMQ的学习(一)(ActiveMQ和JMS的介绍)
    redis总结(持续更新)
    easyUI--搜索条件控件的处理
    bootstrap的下载和引用
    springMVC总结
    easyUi--datagrid的一些处理
    测试工作一
  • 原文地址:https://www.cnblogs.com/hadex/p/7763047.html
Copyright © 2011-2022 走看看