Kevin Burke
Kevin Burke

Reputation: 65024

`cargo package`: error: main function not found

I'm trying to package a library using the cargo package manager for Rust. When I try to run cargo package per the documentation, I get the following output:

error: main function not found
error: aborting due to previous error
failed to verify package tarball

I'm confused. I'm trying to package a library (with useful external functions), so I expect that I don't need a main function. Here is my Cargo.toml:

[package]

name = "package-name"
version = "0.0.1"
authors = [ "Kevin Burke <[email protected]>" ]

Here is my directory structure:

.
├── Cargo.lock
├── Cargo.toml
├── src
│   └── main.rs

What am I missing?

Upvotes: 9

Views: 6574

Answers (1)

Kevin Burke
Kevin Burke

Reputation: 65024

Ah! If you are packaging a library for other programs to use (as I am trying to do), you need to name your file lib.rs.

Alternatively, if you are packaging a binary, name your file main.rs (this was my mistake).

Upvotes: 10

Related Questions