In C/C++, the smallest unit for static linking is obj. If your program invokes a library written in C, your executable normally does not contain all the code of the library, but the objs directly or indirectly used by your program. An obj is either entirely linked or not a single byte linked into the executable, i.e. obj is the smallest linking unit. Am I right?
But what is the case for rust? It seems to me roughly c/c++ library is equivalent to rust crate, and c/c++ obj is equivalent to rust module. But I already see a big difference, c/c++ emits independent obj files, but rust does not emit independent module files. And, is it true that module is the smallest unit for static linking? Furthermore, in rust a module may have submodules while c/c++ does not have sub-objs, which further complicates the issue for rust. If module is indeed the smallest unit, then there are still several possibilities:
- The highest level module (direct child of crate) is the smallest unit.
- The lowest level module is the smallest unit.
- The part of a module except all its submodules is the smallest unit.
Which of the three possibilities is true? or I am totally wrong?