Creating a shared library under Linux?

Jens Mueller jens.k.mueller at gmx.de
Fri Jul 27 00:31:24 PDT 2012


Alex Rønne Petersen wrote:
> On 27-07-2012 07:23, Jens Mueller wrote:
> >Hi,
> >
> >I've read several threads that about creating shared libraries. But I
> >could not make it work.
> >Does anybody know how to create a shared library? I don't care which
> >compiler I have to use to accomplish it.
> >
> >Jens
> >
> 
> Well, all three compilers (DMD, GDC, LDC) can create shared
> libraries at this point. But DMD doesn't actually ship libphobos2
> (druntime+phobos) as a shared library yet, so this is not going to
> work out so well. If, however, you don't use stock libphobos2, you
> can pass -shared -fPIC to create a shared library.

But I can build druntime+phobos as shared libraries and then it should
work with dmd?

> GDC and LDC, as far as I know, can both create shared libraries. GDC
> does it with the standard options you'd pass to GCC. LDC's command
> line is very similar to DMD's if memory serves.

I tried both gdc and ldc but failed. I will write more specifically what
I did later.

> But (another one!): druntime is not yet ready to handle shared
> libraries properly. This means that exceptions thrown across library
> boundaries, TLS, etc are not likely to work properly.

I think I can avoid all of these limitations.

> So, in short: If you're using stock libphobos2, don't bother. If
> you're not using stock libphobos2, you can probably trivially create
> shared libraries.

I see. Then I will try to build a shared libphobos2 first.
Many thanks.

Jens


More information about the Digitalmars-d mailing list