Cross-platform dynamic libraries (GNU/Linux, Mac OS X, Windows, ...)
Gregor Richards
Richards at codu.org
Wed Sep 5 10:55:14 PDT 2007
Hugues De Keyzer wrote:
> Hi,
>
> I'm planning to create a multi-platform (at least GNU/Linux, Mac OS X
> and Windows) application in D. One of its key characteristics is that it
> will be based on modules (plug-ins). Ideally, functionalities more
> advanced than just normal shared libraries would be desirable.
>
> I took a look at DDL, but it seems to be targeted only at Windows.
>
> I made some dlopen() tests on Mac OS X 10.4 with gdc. It works, as long
> as the garbage collector isn't involved in the library. Instancing a
> class in the library works only if new() and delete() are defined and
> don't call the gc. When new() and delete() are not defined, instancing a
> class results in a bus error. gdb gives the following message:
>
> Program received signal EXC_BAD_ACCESS, Could not access memory.
> Reason: KERN_PROTECTION_FAILURE at address: 0x00000000
> 0x0005389a in _d_newclass ()
>
> I also tried calling std.gc.setGCHandle(), but it also fails:
>
> Program received signal EXC_BAD_ACCESS, Could not access memory.
> Reason: KERN_PROTECTION_FAILURE at address: 0x00000000
> 0x00053435 in std.gc.addRange(void*, void*) ()
>
> This may sound like a newbie question, but is there an easy way (or a
> way at all) to develop a cross-platform application in D with shared
> libraries?
>
> Dynamic linking is a very useful feature for software development.
> Including this in the D specification (like threads) would be great.
>
> Hugues De Keyzer
>
> --
> The only constant in life is change
> -- www.wikipedia.org
GDC supports proper .so files on all platforms with .so files. Build the
.so files without a standard library (-no-stdlib or something like that)
and then build the host exporting dynamic symbols (default on OS X,
-rdynamic on everything else). DSSS, of course, does all of this for you.
Windows DLL's will never be capable of full, proper support until phobos
is in a .dll. Even then, if there was conflicting typeinfo, it could
still fail. However, DDL ought to cover it there.
- Gregor Richards
More information about the Digitalmars-d
mailing list