Since std::string
is a template class ( std::string
is only from typedef
to std::basic_string<char>
), only used methods will be used, therefore no unused methods will ever be compiled, and therefore they cannot be removed from your executable file.
As for classes without a template: virtual
functions will always be executed in an executable file, regardless of whether they are called, because vtable needs an address. Other methods (as well as free functions) coming from the source of executable or statically linked libraries will only be linked in binary format if they are actually used. But I do not know which linker flag to print functions that were not related.
On the other hand, a shared library (.so) should include all (exported) functions and methods, since binary code using this shared library can use any (exported) function. But since a shared library can be used by many executables only once during loading into memory, it is usually worth it.
source share