Dynamic loading of shared libraries.

Jens Mueller jens.k.mueller at gmx.de
Mon Jun 13 02:27:23 PDT 2011


Steve Teale wrote:
> Can DMD D2/Linux do this yet?

dmd can't do it yet. But if all you want is to link a against a shared
library you can try the following:

1. Create a shared library
$ gcc -m64 -fPIC -shared shared.c -o libshared.so

2. Building (without linking using dmd)
$ dmd -m64 -c dynamic.d -ofdynamic.o

3. Use gcc as linker
$ gcc -m64 dynamic.o /path/to//libphobos2.a -L. -lshared -lrt -o dynamic

4. Execute
$ ./dynamic
Hello from shared

I attached the files shared.c and dynamic.d, if you want to try
yourself.

Jens
-------------- next part --------------
#include <stdio.h>

void test() {
	printf("Hello from shared\n");
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dynamic.d
Type: text/x-dsrc
Size: 49 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20110613/18eb2b69/attachment.d>


More information about the Digitalmars-d mailing list