Skip to content

Building a binary crate complains about multiple "main" functions #3686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ianh opened this issue Oct 7, 2012 · 2 comments
Closed

Building a binary crate complains about multiple "main" functions #3686

ianh opened this issue Oct 7, 2012 · 2 comments

Comments

@ianh
Copy link

ianh commented Oct 7, 2012

Create main.rs:

fn main() { }

main.rc:

mod main;

Then run:

$ rustc main.rc
main.rs:1:0: 1:13 error: multiple 'main' functions
main.rs:1 fn main() { }
          ^~~~~~~~~~~~~

My rustc was built from git commit 473030.

@ianh
Copy link
Author

ianh commented Oct 7, 2012

Looking at debug output, rust appears to see main and main::main as two functions.

@brson
Copy link
Contributor

brson commented Oct 7, 2012

When Rust sees a .rs file with the same name as a .rc file it automatically builds it as the top level module of the crate, so if you also add 'mod main' it will include the contents of 'main.rs' a second time.

This error happens a lot so this behavior is going to change in #2176

@brson brson closed this as completed Oct 7, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants