And I also don't understand why people like static linking, because obviously, to me, it's useless. Install runtimes on target machine and never bother with static linking ever. Saves file size and a lot of downloading in the end.
Printable View
I find that strange, since the linking process in both cases should only include library functions that are ACTUALLY being used - either explicitly by your code, or by other functions that your code calls. Of course, the implementation of string may well drag in iostream functions that drag in other functionality, ad infinitum. But since the C runtime library used by mingw is the same one that MS uses [albeit possibly different versions/generations], it should make little difference which one you use.
--
Mats
As discussed previously, there is only a saving if the end user is upgrading the application and/or (parts of) the runtime.
Also, the statically linked executable is most likely a fair bit smaller than the entire runtime - because an arbitrary application will use only parts of the runtime, and those are the only components that need to be included in the statically linked executable, whilst the entire DLL(s) of the relevant components will be needed when distributing the runtime as a separate component.
It also avoids the need for an installer - so a standalone application can be one executable file inside a zip file, and that's it. Of course, if you already use an installer for other reasons, then adding the runtime library as an installation item is a small step.
It's a case of "right tool for the job" and "one size doesn't fit all".
--
Mats
Well if i want to make a simple program, or dll, without any installers i dont want them to HAVE to have the runtime and i dont want to have to distribute the runtime dll. I once released a DLL that was made in Visual C and half the people couldnt use it because i didnt realise the runtime thing. I then chose to statically link it, and the file size went up about 400kB EVEN though there is no use of the iostream library in the dll.
It's like this:
MINGW (always uses static linking):
-use iostream stuff -Add 400kB to file size
-use string class -add about 20-30kB to file size
-use STL stuff -varies
Visual C (with static linking):
-Doesnt matter if i use them or not, always adds 400+ kB to file size
There is no problem with statically linking, in fact in mingw that is the only option.
However, it all adds up. When downloading the next application or version of the program, you need to download that excess code again. IF you already if it installed, you don't, and save space.
You don't need an installer anyway.Quote:
It also avoids the need for an installer - so a standalone application can be one executable file inside a zip file, and that's it. Of course, if you already use an installer for other reasons, then adding the runtime library as an installation item is a small step.
Just download the runtime if you haven't previously and all applications will work. No need for an installer.
If they get an error running the program, download the runtime!
Installers are not necessary. Make sure the target machine has the runtime. Everyone should have it.
Then they don't need to download excess code in other applications or in future versions of YOUR applications.
In short: they benefit from it, and your static linking destroys that advantage.
That's the price you pay for static linking.Quote:
MINGW (always uses static linking):
-use iostream stuff -Add 400kB to file size
-use string class -add about 20-30kB to file size
-use STL stuff -varies
Visual C (with static linking):
-Doesnt matter if i use them or not, always adds 400+ kB to file size
I'm not saying you are wrong in your size analyzis - but I suspect you'll find SOMETHING is actually using iostream when you get that sort of file-size. It may well be that your code in itself isn't, but I bet something like the C startup code, or some such does.
--
Mats
Well after some tests i think i may retract my comments about Visual C always linking the iostream library. I can't remember what project made me think it did this, but when i just tested it now, the file size only increases about 50kB when i choose static linking on an almost blank project (which i think is because it uses a newer C library, instead of using the C library that comes with the windows installation). In fact, when testing mingw and Visual C on a larger project (the AngelScript Library) and both of them using static linking for the C++ libraries, the file size is smaller on the Visual C output.