Michael Kilburn wrote: > Hi > > I am quite new with G++/GCC (I came from MSVC world) and currently > having some really annoying problems with GCC. This is the first one: > > I am trying to get equivalent of MSVC's /Oy & /OPT:REF (function-level > linking) with GCC compiler. We have huge project where: > - OS is Linux > - G++ v4.0.3 (afaik) > - ld v2.15 > - everything is C/C++ code and compiled/linked with the same options > - everything is linked statically > - one or two static libraries that makes 98% of executable image size > - executable image size is ~45Mb > > After digging in google I found that these options fed into GCC chain > should do the trick: > -ffunction-sections > -fdata-sections > -Wl,--gc-sections > > And indeed executable size was decreased to ~32Mb. But still it is > wrong -- I have created simple application that just calls empty > function from one of these libraries: > int main() > { > foo(); // foo's body is empty > } > > resulting image size was ~17Mb. If you comment out this call image > size = 5kb. > > > Any ideas how what is wrong? > > Bye. > Sincerely yours, Michael. >
static linking perhaps. In my experience, this is rarely done in unix/linux; it links everything into every executable. You can put your object files into an archive library (*.a - with 'ar'); then link your executables with that lib. This will extract/link from the lib only the object files needed by that executable. Or you can put your object files into (one or more) shared libs (*.so - the unix equivalent of Windows *.DLL); then link your executables with the SO's. Even if multiple executables use the functions in an SO, only one copy of the SO is in memory. _______________________________________________ help-gplusplus mailing list help-gplusplus@gnu.org http://lists.gnu.org/mailman/listinfo/help-gplusplus