Build fully static library by the compiler?
ryuukk_
ryuukk.dev at gmail.com
Sat Aug 10 04:11:04 UTC 2024
On Friday, 9 August 2024 at 22:32:21 UTC, Alex Bryan wrote:
> On Friday, 9 August 2024 at 02:34:03 UTC, Denis Feklushkin
> wrote:
>> We can build static library directly from the compiler:
>>
>> $ ldc2 --lib app.d
>>
>> produces app.a file with app.o inside of it.
>>
>> Are there simple way to make a static library that also
>> includes necessary standard D libraries (i.e., phobos2 and
>> druntime)?
>>
>> Compiler already knows (?) paths to default static libs
>> because it have --static option which produces static
>> executable with all necessary libs inside. (Although I'm not
>> sure that it works by this way)
>>
>> Point is that D can be not a main language of the project and
>> it is unconvient to extract by somehow paths to phobos and
>> druntime at last stages of project build.
>
> ldc2 has the --static option, though, looking from ldc2 --help
> I'm not 100% sure exactly what that does.
>
> If that doesn't work we cat get a little creative:
>
> $ cat hello.d
> import std.stdio;
>
> void main()
> {
> writeln("hello, world!");
> }
> $ ldc2 -c hello.d # creates hello.o
> $ gcc hello.o /usr/lib/x86_64-linux-gnu/libphobos2-ldc.a
> /usr/lib/x86_64-linux-gnu/libdruntime-ldc.a -lm -lz -o hello
> $ ./hello
> hello, world!
> $
I had a similar issue, it almost made me drop D
https://forum.dlang.org/thread/yguvdwlqtyvmjrdsjkzo@forum.dlang.org
Whoever working on that kind of things needs to get this sorted
ASAP
In other languages it is as easy as passing one argument
In D? it's yet again an obfuscated bloat
More information about the Digitalmars-d-learn
mailing list