Author Topic: I'm curious  (Read 7582 times)

PDEE

  • Guest
I'm curious
« on: July 21, 2006, 01:32:34 am »
well i finally got my codeblocks nightly onto suse 10.1. Now i was trying it out and testing to see if all was well. I'm not as advanced as most of you guys at programming. Why on a windows system when building a simple program to test codeblocks with a hello world program i get an exe of nearly 300Kb? Now on the linux one it is only 8Kb, they are the same programs. All the settings are the same. What makes it different? You are probably wondering why i ask, well i would like to know as much as i can about why things work the way they do programming wise.

Anyway, like i said, i'm curious.

Thank You
PDEE

takeshimiya

  • Guest
Re: I'm curious
« Reply #1 on: July 21, 2006, 01:39:37 am »
On linux (GCC), you're linking with stdc++ dinamically.
On windows (GCC MinGW), you're linking to it statically.

Quote
C++ programs using the Standard Template Library (ie/ #include <iostream>) cause a large part of the library to be statically linked into the binary. The need to statically link the stdc++ into the binary is two fold. First MSVCRT.dll does not contain C++ stdlib constructs. Second the legal implications of generating a libstdc++.dll are restricted by the licensing associated with the library. If you wish to keep your file size down use strip to remove debugging information and other verbatim found in the binary.

strip --strip-all SOMEBINARY.exe

sethjackson

  • Guest
Re: I'm curious
« Reply #2 on: July 21, 2006, 03:08:13 am »
On linux (GCC), you're linking with stdc++ dinamically.
On windows (GCC MinGW), you're linking to it statically.

Quote
C++ programs using the Standard Template Library (ie/ #include <iostream>) cause a large part of the library to be statically linked into the binary. The need to statically link the stdc++ into the binary is two fold. First MSVCRT.dll does not contain C++ stdlib constructs. Second the legal implications of generating a libstdc++.dll are restricted by the licensing associated with the library. If you wish to keep your file size down use strip to remove debugging information and other verbatim found in the binary.

strip --strip-all SOMEBINARY.exe

* Sigh *

Funny thing is on my OpenBSD 3.9 system with GCC 3.4.5 + patches Hello World is ~163 KB. :P

Anyways I wish MinGW could produce smaller executables without the strip command.....

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: I'm curious
« Reply #3 on: July 21, 2006, 03:38:44 am »
Quote from: seth
Anyways I wish MinGW could produce smaller executables without the strip command.....
Me too :)

It's a shame they use that old MSVCRT DLL and the project to code a replacement died. It's also a shame trying to compile GCC to produce DLLs didn't work (it was totally ignored and produced the same result).

In fact, in my old days of #allegro, that was a thing some people didn't like about using C++.

takeshimiya

  • Guest
Re: I'm curious
« Reply #4 on: July 21, 2006, 06:38:08 am »
The good thing is that there is always stlport.
You can link indeed to it dynamically with MinGW.

The OGRE guys use (in Windows) stlport over stdc++ for a couple of reasons. I've tested it and works without problems. :)
« Last Edit: July 21, 2006, 06:40:51 am by Takeshi Miya »

PDEE

  • Guest
Re: I'm curious
« Reply #5 on: July 21, 2006, 01:40:01 pm »
Thanks Takeshi.

Moving from windows to linux is all different for me. Well at least i know why now. When i strip the file i get 4Kb  :shock:. I'm going to read up some more on this.

Thank You
PDEE

sethjackson

  • Guest
Re: I'm curious
« Reply #6 on: July 21, 2006, 01:50:14 pm »
The good thing is that there is always stlport.
You can link indeed to it dynamically with MinGW.

The OGRE guys use (in Windows) stlport over stdc++ for a couple of reasons. I've tested it and works without problems. :)

I tried that. However with Digital Mars (didn't try it with MinGW) it produced about the same size executable as MinGW with stdc++....... I may have to give it another go around. :)

takeshimiya

  • Guest
Re: I'm curious
« Reply #7 on: July 26, 2006, 01:11:23 am »
The good thing is that there is always stlport.
You can link indeed to it dynamically with MinGW.

The OGRE guys use (in Windows) stlport over stdc++ for a couple of reasons. I've tested it and works without problems. :)

I tried that. However with Digital Mars (didn't try it with MinGW) it produced about the same size executable as MinGW with stdc++....... I may have to give it another go around. :)
Which makes perfect sense, since the stlport bundled with DMars is compiled statically.
But if you compile stlport and link to it dinamically, the situation will change :wink:

sethjackson

  • Guest
Re: I'm curious
« Reply #8 on: July 26, 2006, 02:14:20 pm »
The good thing is that there is always stlport.
You can link indeed to it dynamically with MinGW.

The OGRE guys use (in Windows) stlport over stdc++ for a couple of reasons. I've tested it and works without problems. :)

I tried that. However with Digital Mars (didn't try it with MinGW) it produced about the same size executable as MinGW with stdc++....... I may have to give it another go around. :)
Which makes perfect sense, since the stlport bundled with DMars is compiled statically.
But if you compile stlport and link to it dinamically, the situation will change :wink:

Oh ok I see. :)