# Cargo工具

## 介绍

Cargo 是 Rust 的构建系统和包管理器

查看版本`cargo --version`

## 使用 Cargo 创建项目

```
$ cargo new hello_cargo
$ cd hello_cargo
```

Cargo创建的目录如下：

![](/files/-LokoUpf2GV6tngrZgef)

`Cargo.toml`为配置文件：

```
[package]
name = "hello_cargo"
version = "0.1.0"
authors = ["425776024 <425776024@qq.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
```

## 使用Cargo编译运行

```
hello_cargo % cargo build
Compiling hello_cargo v0.1.0 (.XXX/hello_cargo)
    Finished dev [unoptimized + debuginfo] target(s) in 0.99s
```

多出来一些编译文件，可执行文件在target/debug/hello\_cargo，首次运行 `cargo build` 时，也会使 Cargo 在项目根目录创建一个新文件：Cargo.lock。这个文件记录项目依赖的实际版本，自动的不用管

![](/files/-LokoUplVmnNpeBUMvNV)

运行：

```
./target/debug/hello_cargo
Hello, world!
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://im-qianuxn.gitbook.io/pytorch/ji-suan-ji/rust/cargo-tool.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
