`rustc --emit=obj` vs. `cargo ...`

I know how to get object output with rustc. What if I want to build an entire cargo project into an object? What command-line flags should I pass to what program?

In Cargo.toml set crate-type = ["staticlib"]. It will produce /target/*/nameofyourproject.a. If you absolutely need .o files, then you can use ar x to get them out of the .a archive.

It will be more than one object file, because that's how Cargo projects are built. If you need an object for linking with a larger project, the static library is as good as an object file.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.