Modern C++ Lamentations

Jonathan M Davis newsgroup.d at jmdavisprog.com
Tue Jan 1 22:34:24 UTC 2019


On Tuesday, January 1, 2019 1:59:25 PM MST Rubn via Digitalmars-d wrote:
> On Tuesday, 1 January 2019 at 19:28:36 UTC, Jonathan M Davis
> wrote:
> > On Tuesday, January 1, 2019 7:04:42 AM MST Rubn via
> >> Druntime and Phobos can be used as shared libraries? What is
> >> this magical feature?
> >>
> >> -Windows User
> >
> > LOL. Personally, it's a feature that I avoid like the plague,
> > because I hate it when my programs stop working just because I
> > updated dmd (which would be bad enough for a normal user, but
> > it's particularly nasty when you're frequently following master
> > and making local changes, because you're working on Phobos,
> > druntime, and/or dmd). But yeah, when I saw the difference in
> > size that H.S. Teoh was seeing, my first thought was that one
> > was probably using Phobos as a shared library while the other
> > was using it as a static one.
> >
> > - Jonathan M Davis
>
> On linux the version should be part of the filename, and iirc
> it'll only try the shared library without a version if it can't
> find the one it needs. Not too familiar with how it is done on
> Windows as it isn't really standardized. Could just look at how
> it is done for the C++ runtime, as I usually have 20 different
> versions of it installed even for the same MSVC year revision. I
> just stick the dll in the same folder as the executable.
>
> I'd rather have a single shared library than having 20 instances
> of it loaded in my 20 dll files.
>
> I can dream though, that one day this fundamental feature will be
> added to D.

The version number is in the file name for Phobos' shared library, but if
you're building the development version, that really doesn't help you,
because every time you rebuild it, you get a file with the same name but
potentially different contents (at least until the next release gets tagged,
and the version number gets bumped). If you're only using releases, you
don't have that problem. However, unless you keep older versions of the
shared library around, as soon as you update, all of your D programs break,
because the version they need isn't there anymore. All in all, it's just way
simpler to use Phobos as a static library. Sure, when you have a bunch of D
programs statically linked, it takes up a few extra megabytes that way, but
when systems have terabytes, that doesn't really matter. Anyone who wants to
use the shared library version is free to do so, but I really don't think
that it makes sense in most cases. I do agree that shared library support in
general is something that we should have, but that doesn't mean that it
really makes sense as the default for the standard library - especially when
so much of it is templated anyway.

I really have no clue what the situation is with dll support, because I
pretty much only program on Windows when I'm forced to, but given how dlls
work on Windows, I've never been a fan of using them except in cases where
you have to. The whole nonsense where you have to rebuild your program,
because _anything_ changed in the dll is just ridiculous IMHO. At least on
*nix systems, shared libraries can be changed so long as the ABIs of the
existing symbols aren't changed, making it so that you can actually update
shared libraries without rebuilding everything. We just get screwed with D,
because the way it's designed makes it very hard to maintain ABI
compatibility if templates are involved, and no attempt is made to maintain
ABI compatibility across versions of Phobos. So, for Phobos, using a shared
library can be very problematic (whereas a shared library with minimal
templates that was designed to maintain a fixed API and ABI would work just
fine, just like it does with C).

- Jonathan M Davis





More information about the Digitalmars-d mailing list