On Thursday, 27 September 2012 at 05:52:44 UTC, Jens Mueller
wrote:
Maxim Fomin wrote:
You can build shared libraries on linux by manually compiling object
files and linking them. On windows last time I tries it was not
possible.

Can you give detailed steps for doing this on Linux? Because nobody as
far as I know has made this work yet?

Jens

Dpaste seems not working, so, sorry for code

----lib.d---
import std.stdio;

static this()
{
        writeln("module ctor");
}

static ~this()
{
        writeln("module dtor");
}

class A
{
        private string text;;
        this(string text)
        {
                writeln("class ctor");
                this.text = text;
        }
        void tell()
        {
                writeln(this.text);
        }
        ~this()
        {
                writeln(this.text);
                writeln("dtor");
        }
        static this()
        {
                writeln("static ctor");
        }
        static ~this()
        {
                writeln("static dtor");
        }
}
---------------
-----main.d----
import lib;

void main()
{
        auto a = new A("some text");
        a.tell();
}
---------------

dmd -c -fPIC lib.d
gcc -shared lib.o -o liblib.so
dmd -c main.d
gcc main.o -llib -lphobos2 -lrt -lpthread -L. -Wl,-rpath=.
./a.out
ldd a.out
        linux-vdso.so.1 (0x00007fff703ff000)
        liblib.so => ./liblib.so (0x00007f48158f1000)
        librt.so.1 => /lib64/librt.so.1 (0x00007f48156cd000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f48154b1000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f481510c000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f4815af4000)

Reply via email to