questions about link

C

Chameleon

My project uses many libraries like libjpeg, libpng and more.
With all of these libraries linked statically and with many .cpp files
of my project, a big binary executable is predictable.

I'm impressed when I was remove the code inside 'main(...)' and all of
the includes, but executable size doesn't change, at all.

There are many *.cpp files but in test.cpp which implements 'main' there
is only this code:
----test.cpp--------
int main(int argc, char **argv)
{
return 0;
}
--------------------

size for this executable is about 290KBs and inside binary I recognize
parts of zlib library. I use zlib library in other .cpp file than
test.cpp, but I don't call anything from this file and if I remove it,
all work ok and size decreases.
If I remove all files except test.cpp, it compiles fine and size is 10KBs.

So the question is why linker include useless binary objects to final
binary executable.

My compiler/linker is mingw-g++, if does matter.
 
R

red floyd

Chameleon said:
[redacted]

Linker behavior is not defined by the language, as well as being
tool-specific, and is thus off-topic of this newsgroup.
>
> My compiler/linker is mingw-g++, if does matter.

Yes, it does, it allows me to direct you to the proper newsgroup. Try
gnu.g++.help.
 
V

Victor Bazarov

Chameleon said:
My project uses many libraries like libjpeg, libpng and more.
[..executable size depends on libraries linked to..]
So the question is why linker include useless binary objects to final
binary executable.

My compiler/linker is mingw-g++, if does matter.

The language does not define how libraries are linked to, and what
the resulting executable size should be. Your question is not really
possible to asnwer in terms of the language. Your best bet is to ask
in the newsgroup dedicated to your compiler/linker or your OS (where
linking is actually defined). My guess would be that the library has
some static objects which get inserted in your executable and their
presence requires a bunch of object modules to be pulled in...

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top