Compiling a shared library

Jonathan M Davis jmdavisProg at
Fri Jan 14 00:58:15 PST 2011

On Friday 14 January 2011 00:49:12 Mandeep Singh Brar wrote:
> Hi,
> I read on this website that it is possible to create shared libraries on
> linux using dmd. Is that correct?
> I am trying to compile the following code:
> module testPlugin;
> import std.stdio;
> export class testPlugin {
> 	export void testMethod() {
> 		writeln("This is method from plugin");
> 	}
> }
> using the command
> dmd -fPIC testPlugin.d -L-shared
> The system gives me the error
> //usr/lib/libc_nonshared.a(elf-init.oS): relocation R_386_GOTOFF against
> undefined hidden symbol `__init_array_end' can not be used when making a
> shared object
> /usr/bin/ld: final link failed: Bad value
> I tried to compile the file first with -c and then create a shared object
> but again it gives the same message.
> Can you please let me know if i am doing something wrong here or is it even
> possible to create a linux shared library using dmd.

I'm not sure what the exact state of shared libraries and dmd is at the moment, 
but as I understand it, it doesn't quite work right now. Getting shared 
libraries working will be one of the priorities once the 64-bit port of dmd is 
done, but until then, I don't believe that you can do it.

- Jonathan M Davis

More information about the Digitalmars-d-learn mailing list