Build fully static library by the compiler?

kinke noone at nowhere.com
Sun Aug 11 11:40:39 UTC 2024


On Sunday, 11 August 2024 at 11:08:24 UTC, Denis Feklushkin wrote:
>> Similar to how people can avoid explicitly linking GNU's 
>> libstdc++ / LLVM's libc++ by using `c++` instead of `cc` as 
>> linker driver, thereby not having to know which implementation 
>> of the C++ std library to choose for the particular platform.
>
> Maybe in D case it will be right choice to respect 
> --defaultlib= setting during static linking? So if anyone wants 
> to link static library without stdlibs then just can leave it 
> empty. In other cases druntime and phobos will be linked into 
> static library?

This is NOT static **linking**, what you are asking for is 
merging the D-default static libraries into a generated static 
lib, to make it 'standalone' and thus simplify linking D parts 
into another project. Merging druntime and Phobos into a static 
lib is an extremely exotic case, analogous to someone wanting to 
merge a static libstdc++.a into their static C++ lib. So I don't 
see a good reason to support this use case by the compiler 
directly.

What you could e.g. do with a dedicated ldc2.conf is specifying 
the paths to druntime and Phobos as regular default switches. 
Then they'll be merged into all static libraries that you create 
with that config file. Compilations are unaffected. [I guess 
linking would still work, but note that even with `-defaultlib=`, 
druntime and Phobos would be in every generated static lib *and* 
additionally in the linker cmdline.]


More information about the Digitalmars-d-learn mailing list