help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Q1: function-level linking is not working as expected


From: Larry Smith
Subject: Re: Q1: function-level linking is not working as expected
Date: Wed, 25 Apr 2007 02:06:47 GMT
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.2) Gecko/20061107 SUSE/1.1.1-0.1 SeaMonkey/1.1.1

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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]