Dylibs and rustc

I recognise I'm trying something slightly odd here, but it still feels like it should work.

In short, I'm trying to use a combination of using cargo to build a public crate, but then use rustc directly to compile my own code (basically because I'm trying to integrate with an existing build system).

I build a given public crate using cargo, with type dylib - that works fine and produces a .so at target/debug/.

I'm then trying to use that dylib from my own source using rustc directly:

rustc -C prefer-dynamic -L target/debug/ --emit obj -o hello_world.o hello_world.rs

This fails with:

error[E0460]: found possibly newer version of crate unicode_widthwhichprettytable depends on

If I instead pick up all the cargo dependencies by using a different -L path:

rustc -C prefer-dynamic -L target/debug/deps/ --emit obj -o hello_world.o hello_world.rs

Then I get:

error: cannot satisfy dependencies so std only shows up once

(repeated with 17 errors for each crate.)

Is there a sensible way to get this to work? Or does what I'm trying to do just not seem viable?

Thanks,
Jon

So this turned out to be a problem with my sysroot in the end; the dynamic library for libstd had gone missing, and so was being statically linked into the crates. That then caused the later errors when trying to use the crates.

RUSTC_LOG, and specifically "RUSTC_LOG=rustc_metadata::dependency_format=debug" were really useful for debugging this.

Jon