Dynamic loading of shared libraries.

Brad Roberts braddr at puremagic.com
Mon Jun 13 18:20:37 PDT 2011


On Mon, 13 Jun 2011, Jens Mueller wrote:

> There have been some posts regarding support for shared libraries. On
> top of my head there we're at least 5 things that need to be done to get
> it working.
> $ dmd -m64 -L-shared shared.d -oflibshared.so
> /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib/crt1.o: relocation R_X86_64_32S against `__libc_csu_fini' can not be used when making a shared object; recompile with -fPIC
> /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib/crt1.o: could not read symbols: Bad value
> collect2: ld returned 1 exit status
> --- errorlevel 1
> 
> I do not fully understand the error. But I believe there is something
> wrong with dmd generating PIC.
> 
> Jens

When building a shared library, you must build with -fPIC.  That's likely 
not sufficient to get it actually fully working with dmd.

so:  dmd -m64 -fPIC -L-shared shared.d -oflibshared.so

That said, combining not-well-tested .so support with 64 bit is a good way 
to discover new bugs, so go for it! :)

Later,
Brad



More information about the Digitalmars-d mailing list