How to build a static lib properly?
Steven Schveighoffer
schveiguy at gmail.com
Mon Mar 6 04:37:09 UTC 2023
On 3/5/23 9:09 PM, ryuukk_ wrote:
> On Monday, 6 March 2023 at 02:00:16 UTC, Mike Parker wrote:
>> This is not dub's fault. When building a shared library, there's a
>> link step, so any external dependencies are linked into the shared
>> library just as they are with an executable. There is no link step
>> with a static library. That means when you build your executable, you
>> need to also link the static library's dependencies along with it.
>>
>> Most of the symbols in your list appear to come from the packages
>> listed in the dependencies section of DCD's dub.json:
>>
>> https://github.com/dlang-community/DCD/blob/master/dub.json
>>
>> So if you want to do this manually, with DCD as a static library, then
>> you also need to build all of those dependencies and link them with
>> your executable.
>
Well, you can create a library that contains all the static libraries,
you just can't use dub to do it for you automatically, or even manually
(dub ignores `.a` files when specified as source files).
> 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
>
Dub expects to have dub-built artifacts available to link. This problem
only occurs if you are building outside of dub, without proper
dependency management.
Dub indeed does not play nice with exporting artifacts for other build
systems. It's something that should be addressed.
Keep in mind though, that you still need to specify any shared library
dependencies, since static libs cannot contain shared libraries or
automatic references to them.
-Steve
More information about the Digitalmars-d-learn
mailing list