Oddities with gcc/g++ linkage

Martin von Loewis martin@mira.isdn.cs.tu-berlin.de
Sun Sep 20 17:05:00 GMT 1998

> On my machine that gives a binary executable size of 44k!
> On my machine this gives me a binary executable size of 3k!!
> Can anyone explain such variances in binary size?

I get the same results, probably because I'm using the same
configuration (i386-pc-linux-gnu). To investigate, I run

g++ -o a a.cc -v --save-temps

This tells me that input, preprocessor output, assembler code, and
object file are about the same size in both cases. So it must be the
linking. Therefore, I run

g++ -o a a.cc -Wl,--verbose 

(assuming a GNU linker). The difference becomes quite clear, now:
libstdc++ is linked as well. ld takes the objects

stdstrbufs.o streambuf.o filebuf.o stdstreams.o

from this library, and needs some more libgcc objects in turn.

I'm not entirely sure *why* this is happening. I believe it is a libio
feature, where libio comes from libstdc++ in this case, instead of
libc. Adding -lc doesn't help, because libstdc++ is searched first.


More information about the Gcc mailing list