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!
    $

  • Build fully stat... Denis Feklushkin via Digitalmars-d-learn
    • Re: Build f... Alex Bryan via Digitalmars-d-learn
      • Re: Bui... ryuukk_ via Digitalmars-d-learn
      • Re: Bui... Denis Feklushkin via Digitalmars-d-learn
        • Re:... ryuukk_ via Digitalmars-d-learn
          • ... Denis Feklushkin via Digitalmars-d-learn
    • Re: Build f... kinke via Digitalmars-d-learn
      • Re: Bui... Denis Feklushkin via Digitalmars-d-learn
        • Re:... kinke via Digitalmars-d-learn
          • ... Denis Feklushkin via Digitalmars-d-learn
            • ... kinke via Digitalmars-d-learn
              • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn

Reply via email to