Thread overview
Creating a .so shared object on linux.
Mar 16, 2005
Daan Oosterveld
Mar 16, 2005
John Reimer
Mar 16, 2005
Anders Runesson
Mar 16, 2005
John Reimer
Mar 17, 2005
Daan Oosterveld
March 16, 2005
Hi,

How do you create a .so shared object library on linux with DMD? I really like shared object libraries and saving memory space ;)

I use the dmd compiler to link the .so with this command:

dmd -L-shared -of/home/daan/purplecat/lib/default/libmysolibrary.so <object files here>

I also tried to use gcc for linkage but both give me this error:

/usr/bin/ld: /home/daan/purplecat/lib/default/libmysolibrary.so: undefined versioned symbol name _d_throw@4
/usr/bin/ld: failed to set dynamic section sizes: Bad value

All other symbols get resolved except this one :(

I am using 0.118, the program does compile when I use static linking.

Or is it impossible to create an .so library? (which would be silly)


Daan
March 16, 2005
Daan Oosterveld wrote:
> Hi,
> 
> How do you create a .so shared object library on linux with DMD? I really like shared object libraries and saving memory space ;)
> 
> I use the dmd compiler to link the .so with this command:
> 
> dmd -L-shared -of/home/daan/purplecat/lib/default/libmysolibrary.so <object files here>
> 
> I also tried to use gcc for linkage but both give me this error:
> 
> /usr/bin/ld: /home/daan/purplecat/lib/default/libmysolibrary.so: undefined versioned symbol name _d_throw@4
> /usr/bin/ld: failed to set dynamic section sizes: Bad value
> 
> All other symbols get resolved except this one :(
> 
> I am using 0.118, the program does compile when I use static linking.
> 
> Or is it impossible to create an .so library? (which would be silly)
> 
> 
> Daan

It's still /not/ possible to make a shared library on Linux.  It's definitely been high on the Linux users wish list, though, for dmd.  I'm not sure if gdc has succeeded yet either.

But, if it did work, I think you have to provide -pic (along with -shared) to activate position independent code for the shared library.

-JJR
March 16, 2005
John Reimer wrote:
 > It's still /not/ possible to make a shared library on Linux.  It's
> definitely been high on the Linux users wish list, though, for dmd.  I'm not sure if gdc has succeeded yet either.
> 
> But, if it did work, I think you have to provide -pic (along with -shared) to activate position independent code for the shared library.
> 
> -JJR

GDC can indeed create shared objects, though I haven't tried actually using one of the generated objects so I'm not sure if it *really* works.

Just pass -fPIC -shared when linking with gdc and you're set.

/Anders Runesson
March 16, 2005
Anders Runesson wrote:
> John Reimer wrote:
>  > It's still /not/ possible to make a shared library on Linux.  It's
> 
>> definitely been high on the Linux users wish list, though, for dmd.  I'm not sure if gdc has succeeded yet either.
>>
>> But, if it did work, I think you have to provide -pic (along with -shared) to activate position independent code for the shared library.
>>
>> -JJR
> 
> 
> GDC can indeed create shared objects, though I haven't tried actually using one of the generated objects so I'm not sure if it *really* works.
> 
> Just pass -fPIC -shared when linking with gdc and you're set.
> 
> /Anders Runesson


Yes... I should have clarified: they can be /created/ successfully with dmd on linux too.  But they don't work when you try to link to them. gdc might have the same problem.

-JJR

PS thanks for the -fPIC correction. :-)
March 17, 2005
John Reimer schreef:
> Anders Runesson wrote:
> 
>> John Reimer wrote:
>>  > It's still /not/ possible to make a shared library on Linux.  It's
>>
>>> definitely been high on the Linux users wish list, though, for dmd.  I'm not sure if gdc has succeeded yet either.
>>>
>>> But, if it did work, I think you have to provide -pic (along with -shared) to activate position independent code for the shared library.
>>>
>>> -JJR
>>
>>
>>
>> GDC can indeed create shared objects, though I haven't tried actually using one of the generated objects so I'm not sure if it *really* works.
>>
>> Just pass -fPIC -shared when linking with gdc and you're set.
>>
>> /Anders Runesson
> 
> 
> 
> Yes... I should have clarified: they can be /created/ successfully with dmd on linux too.  But they don't work when you try to link to them. gdc might have the same problem.
> 
> -JJR
> 
> PS thanks for the -fPIC correction. :-)

Passing -fpic did give me a shared object with dmd as the compiler and gcc for linking. But when linking the .so to an executable it gave the same _d_throw@4 unresolved symbol.

_d_throw? ... exception handling?

I am going to try gdc. If that won't work I'll have to stick to static linking for a while ... ar ar ar ;)

tnx for the info

..Daan