On 6/13/11 10:33 AM, Jens Mueller wrote:
Andrei Alexandrescu wrote:
On 6/13/11 4:27 AM, Jens Mueller wrote:
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

Jens,


Two questions - first, what steps do we need to take to convince the
linker call from within dmd to work as above?

Never thought about that. Just tried.
$ dmd -m64 dynamic.o /path/to/libphobos2.a -L-L. -L-lshared -L-lrt -ofdynamic
works.

Great. Wonder why the path to Phobos is still needed - does using -L preclude all implicit uses of it?

Second, how about the converse - loading a shared library from a
program written in either C or D?

Don't know exactly what you mean. As far as I know dmd is not able to
generate shared libraries. Is that your question?

Yah, I was wondering if it's just PIC generation or something extra.


Andrei

Reply via email to