Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`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?

like image 559
Kevin Burke Avatar asked Jan 19 '15 05:01

Kevin Burke


1 Answers

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).

like image 199
Kevin Burke Avatar answered Oct 25 '22 03:10

Kevin Burke