I
I
IkaR492014-10-17 09:34:34
C++ / C#
IkaR49, 2014-10-17 09:34:34

Why does an iostream program weigh so much more than a stdio one?

I am writing in C++, MinGW compiler, using static linking.
Created two empty projects, connected to one, to the other (actually, the projects are as empty as possible ).
After compilation, I use strip (I cut debugging information from the executable file) (actually, the launch commands are )
After compilation, two files:
kiss_7kb.1413497083.jpg
The screenshot shows the whole essence of my question. Why does a program with the iostream library take up almost 70 times more space than an absolutely similar program with the stdio library?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
AxisPod, 2014-10-17
@AxisPod

Well, firstly, you need to compile in the release (in your case, you need to enable optimization, at least O2) and no strip is needed. And so you get unoptimized code, with a bunch of garbage, but without debugging information. As a result, you will get completely different numbers.
Second, iostream is a template class, with many different template dependencies. Much more code is generated.
Thirdly, we do not see the code and it is not clear what you have done there.
Fourth, we don't know how you compile.
I can say one thing, if you want to get a detailed answer, give detailed information. And there are many factors, but the fact is that yes, the executable file will be larger.
PS And fifthly, you have already been told about static linking, in this case all the necessary code of the statically linked library will be placed in the executable file.

J
jcmvbkbc, 2014-10-17
@jcmvbkbc

Before stripping, run the binary through nm - it will tell you what's in there.

S
s0L, 2014-10-17
@s0L

The answer is in your question, "using static linking". You include the standard cpp library, that's more.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question