Thread overview | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 26, 2012 dynamic library building and loading | ||||
---|---|---|---|---|
| ||||
Haven't done any dynamic linking with D and I need to. I'm using dmd 2.058/Linux at work to build and use dynamic libraries. Here's my attempt: *** Makefile all: main lib.so main: main.d dmd main lib.so: lib.d dmd -fPIC -shared lib.d -of./lib.so *** lib.d extern(C) int fun(string s) { return 42; } *** main.d import std.stdio; void main() { } Running make prints: dmd -fPIC -shared lib.d -of./lib.so /usr/bin/ld: /mnt/vol/engshare/third-party/centos5.2-native/dmd/dmd-2.058-centos5.2-native/bin/../../../../centos5.2-native/phobos/phobos-2.058/ffad884/generated/linux/release/64/libphobos2.a(minfo.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC /mnt/vol/engshare/third-party/centos5.2-native/dmd/dmd-2.058-centos5.2-native/bin/../../../../centos5.2-native/phobos/phobos-2.058/ffad884/generated/linux/release/64/libphobos2.a: could not read symbols: Bad value collect2: ld returned 1 exit status What steps do I need to take to get off the ground? Thanks, Andrei |
September 26, 2012 [OT: Windows note] Re: dynamic library building and loading | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | 26.09.2012 21:58, Andrei Alexandrescu пишет: > Haven't done any dynamic linking with D and I need to. I'm using dmd > 2.058/Linux at work to build and use dynamic libraries. Sorry for the OT (as you are a Linux user), but if you will ever do it on Windows, be aware of this nasty trap: http://d.puremagic.com/issues/show_bug.cgi?id=8130 -- Денис В. Шеломовский Denis V. Shelomovskij |
September 26, 2012 Re: dynamic library building and loading | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Wednesday, 26 September 2012 at 17:57:29 UTC, Andrei Alexandrescu wrote: > Haven't done any dynamic linking with D and I need to. I'm using dmd 2.058/Linux at work to build and use dynamic libraries. Here's my attempt: Maybe it will help you D: https://bitbucket.org/AnyCPU/codewithd/raw/de0a2f0ea1af/symload.d Fortran: https://bitbucket.org/AnyCPU/codewithd/raw/de0a2f0ea1af/simple.f95 Dmd 2.060 used. DLL on OpenSUSE 64bit compiled with command: gfortran -shared -fPIC -O3 -o simple.so simple.f95 |
September 26, 2012 Re: dynamic library building and loading | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On 2012-09-26 19:58, Andrei Alexandrescu wrote: > Haven't done any dynamic linking with D and I need to. I'm using dmd > 2.058/Linux at work to build and use dynamic libraries. Here's my attempt: > Running make prints: > > dmd -fPIC -shared lib.d -of./lib.so > /usr/bin/ld: > /mnt/vol/engshare/third-party/centos5.2-native/dmd/dmd-2.058-centos5.2-native/bin/../../../../centos5.2-native/phobos/phobos-2.058/ffad884/generated/linux/release/64/libphobos2.a(minfo.o): > relocation R_X86_64_32 against `a local symbol' can not be used when > making a shared object; recompile with -fPIC > /mnt/vol/engshare/third-party/centos5.2-native/dmd/dmd-2.058-centos5.2-native/bin/../../../../centos5.2-native/phobos/phobos-2.058/ffad884/generated/linux/release/64/libphobos2.a: > could not read symbols: Bad value > collect2: ld returned 1 exit status > > What steps do I need to take to get off the ground? You need to properly implement support for dynamic libraries in druntime and DMD. I'm not entirely sure if there are some problems left in DMD, but druntime is definitely not ready yet. In general what needs to be done is to properly handle: * Module infos * TLS * Exception handling tables Martin Nowak has a branch for this: https://github.com/dawgfoto/druntime/tree/SharedRuntime -- /Jacob Carlborg |
September 26, 2012 Re: [OT: Windows note] Re: dynamic library building and loading | ||||
---|---|---|---|---|
| ||||
Posted in reply to Denis Shelomovskij | On 9/26/12 2:25 PM, Denis Shelomovskij wrote:
> 26.09.2012 21:58, Andrei Alexandrescu пишет:
>> Haven't done any dynamic linking with D and I need to. I'm using dmd
>> 2.058/Linux at work to build and use dynamic libraries.
>
> Sorry for the OT (as you are a Linux user), but if you will ever do it
> on Windows, be aware of this nasty trap:
> http://d.puremagic.com/issues/show_bug.cgi?id=8130
Thanks!
Andrei
|
September 26, 2012 Re: dynamic library building and loading | ||||
---|---|---|---|---|
| ||||
Posted in reply to Michael | On 9/26/12 2:59 PM, Michael wrote:
> On Wednesday, 26 September 2012 at 17:57:29 UTC, Andrei
> Alexandrescu wrote:
>> Haven't done any dynamic linking with D and I need to. I'm using dmd
>> 2.058/Linux at work to build and use dynamic libraries. Here's my
>> attempt:
>
> Maybe it will help you
> D:
> https://bitbucket.org/AnyCPU/codewithd/raw/de0a2f0ea1af/symload.d
>
> Fortran:
> https://bitbucket.org/AnyCPU/codewithd/raw/de0a2f0ea1af/simple.f95
>
> Dmd 2.060 used.
>
> DLL on OpenSUSE 64bit compiled with command:
> gfortran -shared -fPIC -O3 -o simple.so simple.f95
>
Thanks. The loading part is very useful, but I'm still lost when it comes to build the shared library itself.
Andrei
|
September 26, 2012 Re: dynamic library building and loading | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On 9/26/12 3:18 PM, Jacob Carlborg wrote:
> Martin Nowak has a branch for this:
>
> https://github.com/dawgfoto/druntime/tree/SharedRuntime
Thanks, I'll follow up with him.
Andrei
|
September 26, 2012 Re: dynamic library building and loading | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | > Thanks. The loading part is very useful, but I'm still lost when it comes to build the shared library itself. > > Andrei Program loads dll at runtime using loader which is configured to load concrete dll file(s). Like in gtkD http://www.dsource.org/projects/gtkd/browser/trunk/src/gtkc/Loader.d |
September 26, 2012 Re: dynamic library building and loading | ||||
---|---|---|---|---|
| ||||
Posted in reply to Michael | On Wednesday, 26 September 2012 at 20:10:47 UTC, Michael wrote:
>> Thanks. The loading part is very useful, but I'm still lost when it comes to build the shared library itself.
>>
>> Andrei
>
> Program loads dll at runtime using loader which is configured to load concrete dll file(s). Like in gtkD http://www.dsource.org/projects/gtkd/browser/trunk/src/gtkc/Loader.d
Loading Shared lib isn't big issues here.
The bigger one is building Shared library (written in D) and running it in host application without issues (EH, shared GC etc).
Andrei, if you find out how to make those things work, please share your findings. I'm also in need of using shared libraries.
And yeah, probably Martin Nowak will be the best bet to get information from.
|
September 26, 2012 Re: dynamic library building and loading | ||||
---|---|---|---|---|
| ||||
Posted in reply to nazriel | > Loading Shared lib isn't big issues here.
>
> The bigger one is building Shared library (written in D) and running it in host application without issues (EH, shared GC etc).
>
> Andrei, if you find out how to make those things work, please share your findings. I'm also in need of using shared libraries.
>
> And yeah, probably Martin Nowak will be the best bet to get information from.
I understand. As I remember on forum were topic with same approach for dll written in D. But I can't find a link.
|
Copyright © 1999-2021 by the D Language Foundation