When a project compiles can you end up with multiple copies of an external library in your compiled lib/bin


#1

Okay so I hope that I describe this well enough. But I am wondering if when you compile what happens in this scenario.

lets say we have liba.rlib and libb.rlib and libc.rlib. Both libb.rlib and libc.rlib have a dependency on liba.rlib. And then libc.rlib has a dependency on libb.rlib. Since libb.rlib is a compiled library and has liba.rlib compiled into it when libc.rlib compiles will it compile another copy of liba.rlib? Or does cargo download the source of all dependancies not the already compiled library then compiles each from their source so you don’t get duplicates?

Duplicate is probably not the correct verbiage here since it kind of implies there may be some sort of conflict. I am not suggesting that since however it is done the compiler seems to handle things. It is just really a question out of curiosity, in the end I suppose the only negative that could come from what I am calling a duplicate is a slightly larger lib/bin file.

If the latter is true and libraries are compiled from source individually and not brought in as precompiled then is the compiler smart enough to only compile the portions of the library that are needed? Meaning it only compiles the modules of a library that you specified you were using with a use expression. For example if my code only has use std::io; will the entire std library get compiled into my lib/bin or just that module?