PHP extension in D
Pavel via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jul 10 13:42:41 PDT 2014
On Wednesday, 9 July 2014 at 23:42:22 UTC, Joakim wrote:
> On Wednesday, 9 July 2014 at 21:30:45 UTC, Pavel wrote:
>> Hello!
>>
>> I've reproduced steps 1-9 on my Ubuntu 14.04 x64 machine, but
>> now I have this errors:
>>
>> root at dlang:~/phpext# dmd -shared speedup_wrap.o dfakemain.o
>> speedup.o -ofspeedup.so
>> /usr/bin/ld:
>> /usr/lib/x86_64-linux-gnu/libphobos2.a(lifetime_485_6c8.o):
>> relocation R_X86_64_32 against `_D15TypeInfo_Shared7__ClassZ'
>> can not be used when making a shared object; recompile with
>> -fPIC
>> /usr/lib/x86_64-linux-gnu/libphobos2.a: error adding symbols:
>> Bad value
>> collect2: error: ld returned 1 exit status
>> --- errorlevel 1
>>
>>
>> I'm new to D/C languages, so what can I do to fix this error?
>> I tried to compile with "-fPIC" option at all appropriate
>> steps, but nothing helps :(
>
> I think Rémy's advice is a little outdated when dealing with
> shared libraries, which are now supported on linux, so the fake
> main is not necessary there anymore:
>
> http://dlang.org/dll-linux.html#dso7
>
> Try linking to phobos as a shared library as shown there and
> then calling the D function, I believe it should work (you'll
> also need to call rt_init() before the D library and rt_term()
> after).
Thank you very much for advice, it helped me :) Here is my
build.sh file after all experiments:
#!/bin/sh
swig -php speedup.i
dmd -m64 -fPIC -c -L-shared speedup.d
sed -i "1i char* d_speedUp(char* arg1);" speedup_wrap.c
gcc `php-config --includes` -fpic -c speedup_wrap.c
dmd -m64 -shared -defaultlib=libphobos2.so
-I/usr/lib/x86_64-linux-gnu speedup_wrap.o speedup.o -ofspeedup.so
Note that we need to insert d_speedUp() function definition in
speedup_wrap.c file, otherwise there will be a warning "cast to
pointer" and segmentation fault when using compiled speedup.so
file:
speedup_wrap.c: In function ‘_wrap_d_speedUp’:
speedup_wrap.c:1141:12: warning: cast to pointer from integer of
different size [-Wint-to-pointer-cast]
Also I found no mention about rt_term() method in generated
files, so my php script works without it.
result = (char *)d_speedUp(arg1);
More information about the Digitalmars-d
mailing list