I have a project that must use a static .lib on windows. I have written a lib crate that interfaces with that .lib. I now have written another rust program that depends on the rust lib crate. When I try to build it I get an error that the static lib cannot be found. I thought that the whole point of a static library was that it is built into the crate and you don't need to continue to carry the static library around. For example in the C++ world if I statically link a library into a binary, I can just hand someone the binary and they can run it, even on another machine if the environments are close enough, they don't need the originally static library. But I can't seem to get this behavior in rust.
-Cargo.toml ( has Name1 as dependency)
This all works if I tell Name2 about the static .lib so that it too can link against it, but I would like to hide this dependency away in the Rust lib crate Name1 so that any future dependencies don't have to know about the C static library and continue to pull that library around for everyone in the world to have to link against it. How do I do this?
If you link static library with binary then you don't need to ship that static library. Both in C/C++ and Rust.
If you link static library with another binary then you need to ship both libraries and link them both. Both in C/C++ and Rust.
Now your question is turned intothis:
Rust behaves precisely and exactly like C and C++ behaved for more than half-century, why is that?
Does that question even need answering? Rust behaves like C and C++ exactly because it's what people should expect. The fact that you don't know how static libraries work in C or C++ is not much of an excuse.
You can use the exact same mechanism that you would use in C and C++. There are bazillion such tools: pkg-config, libtool and many others.
They all are, of course, have different warts and limitations, but that's not something Rust can fix: C and C++ behave like C and C++ always behaved, even if you use them from Rust.