Entry symbol `main` declared multiple times

⚓ rust    📅 2025-05-23    👤 surdeus    👁️ 4      

surdeus

Warning

This post was published 37 days ago. The information described in this article may have changed.

Hello,
I am trying to mix a lib.rs and main.rs files inside the same project.

cargo.toml

[package]
name = "lib_main"
version = "0.1.0"
edition = "2021"

[lib]
name = "lib"
path = "src/lib.rs"
crate-type = ["staticlib", "cdylib"]

lib.rs

#[no_mangle]
pub fn main() {
    println!("{}", "hello lib");
}

main.rs

#[path = "lib.rs"]
mod this;

fn main() {
    this::main();
}

Is it possible ?

Thank you in advance for your help.

4 posts - 3 participants

Read full topic

🏷️ rust_feed