IPB

Welcome Guest ( Log In | Register )

> foobar2000 Development Forum Rules

This forum is for developer discussions only. If you have a problem / bug report / idea / feature request that isn't related to foobar2000 SDK, post it in an appropiate forum instead - tech support questions go to support forum, everything else goes to general forum.
All non-developer posts on this forum will be removed. Continued abuse of this forum will result in admin actions (warnings, account suspension).

2 Pages V   1 2 >  
Reply to this topicStart new topic
Static vs Dynamic linking, Any "official" position
NEMO7538
post Apr 30 2011, 09:34
Post #1





Group: Developer
Posts: 814
Joined: 28-November 03
Member No.: 10088



Is there any "official" position regarding the linking of C++ libraries in 3rd party components (code generation option /MT vs /MD), given that :
Go to the top of the page
+Quote Post
mudlord
post Apr 30 2011, 09:37
Post #2





Group: Developer (Donating)
Posts: 797
Joined: 1-December 07
Member No.: 49165



Static link.
Go to the top of the page
+Quote Post
Zao
post Apr 30 2011, 14:09
Post #3





Group: Members (Donating)
Posts: 884
Joined: 25-September 03
From: Umeň, Sweden
Member No.: 9001



This is how I decide on whether to link the runtime dynamically or statically. If your component is:
  • just a single fb2k DLL - there's really no need to link the runtime dynamically except size reduction, at the cost of annoying your users.
  • a single fb2k DLL with a bunch of companion DLLs - it depends on the kind of the companion DLLs. If their interface is:
    • C-like with create/delete functions and their own types, or if they use PFC - link statically to the runtime.
    • C++-like with use of the standard library in their interfaces or if they use templates - you probably want to link the runtime dynamically.
Don't forget that you can deploy the runtime privately by bundling the two DLLs in your component archive, but I prefer requiring my users to install the redist instead to reduce the size of the component archive.
Notice that the above flowchart doesn't cover the case of having more than one component in an archive, as that's something that you should not ever do.

This post has been edited by Zao: Apr 30 2011, 14:35


--------------------
Zao shang yong zao nong zao rang zao ren zao.
To, early in the morning, use a chisel to build a bathtub makes impatient people hot-tempered.
Go to the top of the page
+Quote Post
viktor
post May 1 2011, 13:31
Post #4





Group: Members
Posts: 297
Joined: 17-November 06
Member No.: 37682



static linking is just bad as it is. there's really no point using it. ms is not the only one who recommends dynamic linking, everyone recommends it who has a clue.

with static linking you make it impossible to have security and/or other updates applied to the crt. they will be applied to the system crt, but the app/dll you linked statically will still be vulnerable. the same applies to the case when you "bundle" dlls with your app. not to mention it makes no sense to have the same crt/lib in your system in several copies, possibly at different patch levels. you can do it, but it makes no sense and is a very very bad practice. it's only widespread because developers are too lazy to take care of things.

use the redist, which is maintained by windows update, or use the wdk method, with which you still use the system crt and other libs which are maintained by windows update. if you wanna try the wdk method, i can give you pointers, i use it with success for xchat-wdk and a lot of other libs.

the redist way is probably easier, it only requires some installer work, i.e. bundling the redist installer into the existing installer, or instructing your users to download and install it (which will cause a lot of bug reports coz users won't read your instructions).

as a sidenote, size is the last consideration nowadays, it just doesn't matter when you can buy a 2TB drive for 50$. you should take care of security and reliabilty first, not size.

This post has been edited by viktor: May 1 2011, 13:38
Go to the top of the page
+Quote Post
lvqcl
post May 1 2011, 14:09
Post #5





Group: Developer
Posts: 3208
Joined: 2-December 07
Member No.: 49183



Dynamically linked components can be problematic for those who use foobar2000 as a portable app.
The solution is simple(?): user can copy msvcr100.dll and msvcp100.dll in foobar2000 folder (I assume that the developer uses MSVS 2010).

And: foobar2000 itself and its official components are linked statically.
Go to the top of the page
+Quote Post
Zao
post May 1 2011, 14:41
Post #6





Group: Members (Donating)
Posts: 884
Joined: 25-September 03
From: Umeň, Sweden
Member No.: 9001



QUOTE (viktor @ May 1 2011, 14:31) *
as a sidenote, size is the last consideration nowadays, it just doesn't matter when you can buy a 2TB drive for 50$. you should take care of security and reliabilty first, not size.

Size does matter on the internet. Both in terms of time it takes for users to download, not hitting transfer caps imposed by evil ISPs, and not to be forgotten, bandwidth costs for the HydrogenAudio server.
As for using the WDK, last I checked it had some rather ancient compilers and runtimes, without a trace of C++0x. If you want to write your C++ without going insane, you will need to use a recent runtime.
If you re-read my post, you'll see that I only advocate using a shared runtime when it's technically unfeasible to use a static runtime or MSVCRT.

As for using "installers", that's not possible with the current foobar2000 component ecosystem which mandates that a component shall be distributed in a self-contained zip file with any dependencies it requires inside. Even if it was, it'd be impossible to use them with portable installs as lvqcl mentions.

The reason why fb2k can get away from having a shared runtime is because it reinvents most of the C++ standard library in PFC, with the shared bits in shared.dll (which everyone must link). It is not feasible to rewrite arbitrary third party code to use PFC.


--------------------
Zao shang yong zao nong zao rang zao ren zao.
To, early in the morning, use a chisel to build a bathtub makes impatient people hot-tempered.
Go to the top of the page
+Quote Post
viktor
post May 1 2011, 14:45
Post #7





Group: Members
Posts: 297
Joined: 17-November 06
Member No.: 37682



QUOTE (lvqcl @ May 1 2011, 15:09) *
Dynamically linked components can be problematic for those who use foobar2000 as a portable app.
The solution is simple(?): user can copy msvcr100.dll and msvcp100.dll in foobar2000 folder (I assume that the developer uses MSVS 2010).

And: foobar2000 itself and its official components are linked statically.


why is that problematic? if you use wdk, your app will run on any windows (xp, vista, 7, 2003, 2008). win2000 penetration is about 0.5% at most, so i wouldn't count that as a showstopper.

"The solution is simple", you see? that's what i'm talking about. you are lazy, you want to get it fast, instead of getting it right.

This post has been edited by viktor: May 1 2011, 14:55
Go to the top of the page
+Quote Post
viktor
post May 1 2011, 14:48
Post #8





Group: Members
Posts: 297
Joined: 17-November 06
Member No.: 37682



QUOTE (Zao @ May 1 2011, 15:41) *
Size does matter on the internet. Both in terms of time it takes for users to download, not hitting transfer caps imposed by evil ISPs, and not to be forgotten, bandwidth costs for the HydrogenAudio server.
As for using the WDK, last I checked it had some rather ancient compilers and runtimes, without a trace of C++0x. If you want to write your C++ without going insane, you will need to use a recent runtime.
If you re-read my post, you'll see that I only advocate using a shared runtime when it's technically unfeasible to use a static runtime or MSVCRT.

As for using "installers", that's not possible with the current foobar2000 component ecosystem which mandates that a component shall be distributed in a self-contained zip file with any dependencies it requires inside. Even if it was, it'd be impossible to use them with portable installs as lvqcl mentions.

The reason why fb2k can get away from having a shared runtime is because it reinvents most of the C++ standard library in PFC, with the shared bits in shared.dll (which everyone must link). It is not feasible to rewrite arbitrary third party code to use PFC.


orly? you are clearly write-only, as you managed to miss the fact that you can actually decrease size if you use wdk. and no, 1mb minus or plus does not matter on the internet anyway. so you are wrong in both cases. i only said that size should be the last point in an argument. users won't give a damn about a few megabytes.

and you also managed to ignore the rest of my post, congrats smile.gif

and no, the wdk does not use ancient compilers. they are actually from vs2008, but you can use even the vs2010 compilers. you only need to use the wdk headers and libs.

This post has been edited by viktor: May 1 2011, 14:51
Go to the top of the page
+Quote Post
kode54
post May 1 2011, 15:15
Post #9





Group: Admin
Posts: 4499
Joined: 15-December 02
Member No.: 4082



Of course, you can forget about using those headers and libraries if you use even an ounce of the STL. It's a good thing nobody uses that.
Go to the top of the page
+Quote Post
Yegor
post May 1 2011, 15:27
Post #10





Group: Developer
Posts: 251
Joined: 8-April 09
From: Russia, Zlatoust
Member No.: 68779



I remember some Wine users complaining about my component's dependency on MSVCR libs :-| And outdated Win XP installations probably lack them too. So I chose static linking. I think that user experience is more important than several kilobytes of an overhead. Still, I'm gonna fill a gap in my linking skills and get executables static and small at the same time.
QUOTE
user can copy msvcr100.dll and msvcp100.dll in foobar2000 folder
That's quite a geeky solution for most users. It's up to developers to care about dependencies.

This post has been edited by Yegor: May 1 2011, 15:41
Go to the top of the page
+Quote Post
Zao
post May 1 2011, 16:01
Post #11





Group: Members (Donating)
Posts: 884
Joined: 25-September 03
From: Umeň, Sweden
Member No.: 9001



I did not say anything about the rest of your post because I didn't find anything worth saying about it, except that I do not consider the "omg, security!" argument a valid argument for software that is not attacker-facing.
Using the WDK headers and libraries is not an option if you write any kind of non-trivial C++. They're really only feasible if you write balls-to-the-wall idiot-grade C.

As for "size doesn't matter on the internet", I'm sure that the guy paying the HA bills disagrees strongly with you.
There's tradeoffs for everything, and in the case of fb2k, it's Really Hard to warrant/support any kind of non-private dynamic deployment. What you do for your own projects is up to you and your closet.


--------------------
Zao shang yong zao nong zao rang zao ren zao.
To, early in the morning, use a chisel to build a bathtub makes impatient people hot-tempered.
Go to the top of the page
+Quote Post
viktor
post May 7 2011, 20:51
Post #12





Group: Members
Posts: 297
Joined: 17-November 06
Member No.: 37682



QUOTE (kode54)
Of course, you can forget about using those headers and libraries if you use even an ounce of the STL. It's a good thing nobody uses that.

QUOTE (Zao)
Using the WDK headers and libraries is not an option if you write any kind of non-trivial C++. They're really only feasible if you write balls-to-the-wall idiot-grade C.


huh? wdk comes with stl, atl, mfc and so on. so what are you bitchin' about without a clue?

QUOTE (Zao)
As for "size doesn't matter on the internet", I'm sure that the guy paying the HA bills disagrees strongly with you.


sure, if he wants a higher bill. i've already mentioned that size would actually decrease, but you're apparently left in write-only mode.

QUOTE (Yegor)
That's quite a geeky solution for most users. It's up to developers to care about dependencies.


nah, it's not "geeky", it's just plain bad. and it's not at all a "solution", rather, it's a workaround of the lazy, clueless "devs" whose only perspective is file size.

This post has been edited by viktor: May 7 2011, 21:02
Go to the top of the page
+Quote Post
mudlord
post May 8 2011, 17:01
Post #13





Group: Developer (Donating)
Posts: 797
Joined: 1-December 07
Member No.: 49165



QUOTE
rather, it's a workaround of the lazy, clueless "devs" whose only perspective is file size.


harhar, so you rather have brainless end users downloading crap JUST to run a teeny component?????


lawl. laugh.gif
Go to the top of the page
+Quote Post
xnor
post May 8 2011, 17:23
Post #14





Group: Developer
Posts: 379
Joined: 29-April 11
From: Austria
Member No.: 90198



QUOTE (viktor @ May 7 2011, 21:51) *
huh? wdk comes with stl, atl, mfc and so on. so what are you bitchin' about without a clue?


edit: nevermind, confused wdk with windows sdk, which does not ship MFC/ATL.

This post has been edited by xnor: May 8 2011, 17:52
Go to the top of the page
+Quote Post
Canar
post May 8 2011, 18:44
Post #15





Group: Super Moderator
Posts: 3327
Joined: 26-July 02
From: princegeorge.ca
Member No.: 2796



Unless you can justify it otherwise, the convention is to use static linking.

We reserve the right to mock you ruthlessly when users come whining about how you failed to properly distribute dynamically-linked versions.

This post has been edited by Canar: May 8 2011, 18:44


--------------------
∑:<
Go to the top of the page
+Quote Post
NEMO7538
post May 8 2011, 19:21
Post #16





Group: Developer
Posts: 814
Joined: 28-November 03
Member No.: 10088



Thanks,
That is the kind of answer I was expecting, in one way or another.
I'll switch to static in my next versions ...

This post has been edited by NEMO7538: May 8 2011, 19:24
Go to the top of the page
+Quote Post
Yegor
post May 9 2011, 05:09
Post #17





Group: Developer
Posts: 251
Joined: 8-April 09
From: Russia, Zlatoust
Member No.: 68779



Given that most (if not all) components are made using either VS 2008 or 2010, wouldn't it be better if the VC redist package was included in the Foobar2000 installer? If I'm not mistaken, it won't make much increase in the installer size as everything will be linked dynamically.

This post has been edited by Yegor: May 9 2011, 05:13
Go to the top of the page
+Quote Post
kerpondile
post May 9 2011, 06:47
Post #18





Group: Developer
Posts: 146
Joined: 26-January 04
Member No.: 11525



How does WDK approach work with 3rd party libs like BOOST? With both static and dynamic linking the linking is easy enough but how about with WDK...? Is it even possible to compile boost "the WDK way" without too much manual work?
Go to the top of the page
+Quote Post
Zao
post May 9 2011, 15:48
Post #19





Group: Members (Donating)
Posts: 884
Joined: 25-September 03
From: Umeň, Sweden
Member No.: 9001



kerpondile:
For Boost.Build, you would have to hack around a fair bit to get it to grok the environments that the WDK provides, as it doesn't care about what's in the path or environment variables. It would probably be feasible though, particularly if you had the assistance of a BBv2 guru in getting it into BBv2's core distribution.
As for other build systems, you would have to hope that they are able to emit nmake build scripts, otherwise you're probably quite hosed.

And then there's of course the fact that the WDK yet again has an outdated SC++L (Standard C++ Library, which people looove to misspell as "STL"), which has several known bugs, and the fact that the compilers in the WDK are VC9 era and thus do not have any C++0x features.

Yegor:
There's not a single VS2008 runtime, there's like 12 over the years with the service pack and all the hotfixes, with a serious versioning hell.
VS2010 has had one update to the runtime with SP1, but the 2010 SP1 runtime is designed to be a drop-in replacement for the RTM runtime without problems.

This post has been edited by Zao: May 9 2011, 16:13


--------------------
Zao shang yong zao nong zao rang zao ren zao.
To, early in the morning, use a chisel to build a bathtub makes impatient people hot-tempered.
Go to the top of the page
+Quote Post
viktor
post May 9 2011, 18:50
Post #20





Group: Members
Posts: 297
Joined: 17-November 06
Member No.: 37682



QUOTE (mudlord @ May 8 2011, 18:01) *
QUOTE
rather, it's a workaround of the lazy, clueless "devs" whose only perspective is file size.


harhar, so you rather have brainless end users downloading crap JUST to run a teeny component?????


lawl. laugh.gif


duh, I CAN'T BELIEVE. you STILL don't get it, please switch back to read-write mode, i'm begging you! would you be so kind as to do at least SOME research before making ridiculous posts like this?

if you compile your app with just VS, users have to download and install the VC redist, but users don't have to download ANYTHING if you compile your stuff with the WDK, that's THE WHOLE POINT of this method.

if my memory serves me correctly, this is at least the third time i explain you can reduce app bundle size with the wdk (and take advantage of dynamic linking AT THE SAME TIME), but you still sound like a broken record... it's not good because... just cause. cause you don't have a clue about it, so it can't work. now, let me tell you... it does. i've compiled zlib, openssl, enchant, nss, xchat and its plugins with the WDK. but nooo it won't work, i know. poor me. please, install xchat-wdk on a fresh install of xp sp0. it will run. it must be black magic i think.

ps: saying that a runtime is obsolete if it's older than 1 year is almost as ridiculous (vc10 came out last year).

This post has been edited by viktor: May 9 2011, 18:59
Go to the top of the page
+Quote Post
xnor
post May 9 2011, 19:19
Post #21





Group: Developer
Posts: 379
Joined: 29-April 11
From: Austria
Member No.: 90198



Personally I also like the dynamic linking idea* with fb2k shipping the runtime library(ies).

*) see msdn/advantages
Go to the top of the page
+Quote Post
mudlord
post May 10 2011, 07:40
Post #22





Group: Developer (Donating)
Posts: 797
Joined: 1-December 07
Member No.: 49165



Fine viktor:
* Does this method allow for usage of project files, or is it some contrived makefile method (which would be useless with FB2K)
* Is there any limit to what this method can compile for? Does it allow C++ with heavy template usage, virtual classes, etc? Is there any security issues or issues with some things like the runtime's vector<> implementation, etc?
* Which version of the MSVC runtime does it link against, the most recent, or just the MSVC6 version?

If points 1 and 2 are settled, I would love to hear more about these methods.....
FB2K especially relies on point 2 being settled in regards to certain C++ features being usable.

This post has been edited by mudlord: May 10 2011, 07:41
Go to the top of the page
+Quote Post
Yegor
post May 10 2011, 09:39
Post #23





Group: Developer
Posts: 251
Joined: 8-April 09
From: Russia, Zlatoust
Member No.: 68779



QUOTE
There's not a single VS2008 runtime, there's like 12 over the years with the service pack and all the hotfixes, with a serious versioning hell.
So? Ship the latest one.
Go to the top of the page
+Quote Post
Zao
post May 10 2011, 10:21
Post #24





Group: Members (Donating)
Posts: 884
Joined: 25-September 03
From: Umeň, Sweden
Member No.: 9001



QUOTE (Yegor @ May 10 2011, 10:39) *
So? Ship the latest one.

2008 is thankfully a closed chapter in the book, as they do not seem to release that many updates anymore.
If it had still been relevant, the latest 2008 runtime is not necessarily in any way backwards compatible with the previous versions of the 2008 runtime.
There's a complex set of forwarding to newer runtimes for some runtime versions, so a bundled "VS2008" runtime would be rather useless for any developers that weren't running exactly the right build environment, which includes among other things having just the right Windows Updates installed. If a newer runtime appears, they might have upgraded "too far".

The above outlines why privately deploying hasn't really been feasible in the past for fb2k.
Microsoft thankfully saw that SxS versioning of the runtime was a bad idea and from 10 and onward have made a backward-compatible regular set of DLLs which helps deployment scenarios like fb2k.

As for "ship the latest one", let's say that fb2k starts shipping VS10 runtimes. What should happen when Dev11 comes out, should it stop bundling the VS10 runtime, breaking any components that rely on it? Should fb2k turn into Nero, with an ever-growing installer?


--------------------
Zao shang yong zao nong zao rang zao ren zao.
To, early in the morning, use a chisel to build a bathtub makes impatient people hot-tempered.
Go to the top of the page
+Quote Post
Yegor
post May 10 2011, 18:17
Post #25





Group: Developer
Posts: 251
Joined: 8-April 09
From: Russia, Zlatoust
Member No.: 68779



Ok, this makes sense.
Go to the top of the page
+Quote Post

2 Pages V   1 2 >
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 17th April 2014 - 19:28