Build fully static library by the compiler?
Alex Bryan
abryancs at gmail.com
Fri Aug 9 22:32:21 UTC 2024
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!
$
More information about the Digitalmars-d-learn
mailing list