Re: Linking in C++
On Apr 28, 7:01 am, gwowen <gwo...@gmail.com> wrote:
On Apr 28, 2:23 pm, d...@furrfu.invalid (Drew Lawson) wrote:
In article <c18b2cb6-1106-4dfc-86d1-2b803b060...@w24g2000yqb.googlegrou=
ps.com>
Ebenezer <woodbria...@gmail.com> writes:
On Apr 27, 2:56 pm, jacob navia <ja...@spamsink.net> wrote:
Le 27/04/11 21:01, Pete Becker a crit :
On 2011-04-27 14:24:21 -0400, Ebenezer said:
On Apr 25, 4:53 pm, James Kanze <james.ka...@gmail.com> wrote:
The granularity of most linkers is the object file. In general,
if you are writing a library, you put each non-virtual function
in a separate object file, and only those which are actually
called are included. (But this is, of course, a quality of
implementation issue for the library provider.)
This seems like a "premature optimization." I haven't come
across this much, but recall your mentioning it previously.
Not in a general-purpose library. If you get it wrong your custome=
rs
complain about code bloat. As an extreme example, linking the enti=
re C
standard library into every application would not be a good thing.
For some people all optimizations are "premature" and they deliver
bloated, unoptimized programs. Code bloat slows down programs becaus=
e
it forces more main memory reads, and makes code cacheing less
efficient. It is a very important optimization.
I think this library --http://quicklz.com-- is a
quality library, but there's no breaking things up
like that. I can't think of a library that splits
things up into such small chunks.
Taking a quick look at libc on my FreeBSD system, I see that it is
split into 849 files. I find this pretty common for general use
libraries.
Less general libraries -- database APIs, toolsets, etc. -- probably
don't take that effort as often.
running
nm /usr/lib/libc.a | grep -F ".o:" | wc -l
on this Ubuntu Linux box suggests 1479 distinct ibject files in the
static library
nm /usr/lib/libc.a 2> /dev/null | grep " T " | wc -l
suggests 2377 defined global symbols, or about 1.5 exported symbols
per object file.
An easier way to do it:
On RHEL 5,
ar tv /usr/lib/libc.a | wc
shows 1391 object files