How to build a static lib properly?
Mike Parker
aldacron at gmail.com
Mon Mar 6 05:59:09 UTC 2023
On Monday, 6 March 2023 at 02:09:23 UTC, ryuukk_ wrote:
>
>
> dub should build a static library for the project i build, that
> includes each library it uses that are referenced as "library"
> since the default is "staticLibrary" according to rikki
What you're asking for is a different use case. `staticLibrary`
is for compiling a specific dub package as a static library. It
does not imply that all of that package's dependencies should
also be compiled into a single static library. Nor should it.
You're asking for a package and its dependencies to be bundled
for use outside of the dub ecosystem as a single static library.
I won't say it's not a legitimate use case, it's just not one
that dub currently supports, nor was it originally intended to (I
wouldn't expect it to be a common one either, but then again
common expectations are always changing).
As a potential dub enhancement, e.g., `staticLibraryBundle`, I do
agree it's worth exploring. I don't believe you can expect every
package to "just work" in that environment. As Steve mentioned,
there will always be link-time dependencies to any shared
libraries on which those bundled libraries depend. And some
packages may be set up in a way that causes issues, as Rikki
noted when he said he had to make some tweaks on his successful
build.
But for the time being, dealing with static libraries in D is
just the same as dealing with them in the C and C++ world. They
always have been a PITA to deal with, and that's why the trend in
recent years has been to move away from them. Build tools like
dub hide them from you when used as intended. It's when you mix
build systems that you run into trouble.
Still, I suggest you send an email to social at dlang.org as part of
the Gripes and Wishes campaign so that this gets added into the
dataset. Anything that enhances dub's usability should be looked
at.
More information about the Digitalmars-d-learn
mailing list