Harry
Harry

Reputation: 2963

Why is an .rlib not generated in the target/debug directory after a successful build with CLion?

I am trying a build a library using the CLion IDE with Rust plugin installed. After a successful build, the library is not generated in the target/debug directory.

This is my project structure:

src/lib.rs

pub mod Math;

src/Math.rs

pub struct Arithmetic {
    x: i32,
    y: i32,
}

impl Arithmetic {
    pub fn new(&mut self, x: i32, y: i32) {
        self.x = x;
        self.y = y;
    }

    pub fn add() -> i32 {
        2 + 3
    }

    pub fn sub() -> i32 {
        2 - 3
    }

    pub fn mul() -> i32 {
        2 * 3
    }

    pub fn div() -> i32 {
        2 / 3
    }
}

Cargo.toml

[package]
name = "Test_Lib"
version = "0.1.0"
edition = "2018"

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

[dependencies]

What am I doing wrong?

Upvotes: 1

Views: 213

Answers (1)

Kornel
Kornel

Reputation: 100100

Your project structure looks fine, and should be building as a Rust library.

But you shouldn't be concerned whether .rlib is built, because the file alone isn't useful for anything other than Cargo's private usage.

If you're trying to make a library usable outside of internal Rust/Cargo usage (such as .dll/.lib or .so/.a), then you will have to use the C ABI or C++ ABI and set crate-type to staticlib or cdylib.

If you want to use this library in other Rust projects, then don't even look into the target directory. Rust libraries aren't manually built one-by-one. Cargo builds the whole dependency tree in one go. Publish your crate on crates.io, or a git repository or add it to another project via path.

Upvotes: 0

Related Questions