Ehem, ARM
Joakim
joakim at airpost.net
Sun Dec 1 05:30:37 PST 2013
On Wednesday, 27 November 2013 at 13:52:17 UTC, Chris wrote:
> On Tuesday, 26 November 2013 at 11:22:59 UTC, Joakim wrote:
>>
>> What JNI-D stuff have you tried and on what platform,
>> linux/x86? I'll try the shared library approach on Android at
>> some point and report back.
>
> If I remember correctly, I did something like this (think it
> was on OS X):
>
> 1. Create D library (seems to be necessary?)
> dmd -lib hello.d -oflibhelloD
>
> 2. Compile (do not link)
> gcc -c hello.c -o helloC.o // Calls D code
>
> 3. JNI (compile)
> gcc -c -I/path/to/Java/Headers Test.c -o Test.o // JNI file
> (calls hello.c)
>
> 4. Create library.
> gcc -dynamiclib -o libTest.jnilib -lphobos2 -lhelloD Test.o
> helloC.o
>
> And it worked. I don't know, if step 2. is necessary at all.
>
> I've also been able to successfully combine Python and D, so
> that the D module could be loaded and used by Python like any
> other module. I could also link D and Objective-C. But that was
> all on Desktop (Mac OS X and Linux). I haven't tried it for
> Android or iOS yet.
Hmm, that seems pretty convoluted, hopefully it won't be as bad
on Android.
I've started porting core.stdc from druntime to Android, so far,
so good. One oddity I've run into is that stderr doesn't work
properly on half of the existing OS platforms. Take this test
file:
//test.d
import core.stdc.stdio;
extern (C) int main() { fputs("doing this for real?", stderr);
return 0;}
It doesn't link on Win32, Win64, or Android. It works on linux
and FreeBSD. Here's the output on platforms where it doesn't
work:
Win 7 x64 with dmd 2.064.2:
C:\dmd2>.\windows\bin\dmd.exe -m32 test.d
OPTLINK (R) for Win32 Release 8.00.13
Copyright (C) Digital Mars 1989-2010 All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
test.obj(test)
Error 42: Symbol Undefined _stderr
--- errorlevel 1
C:\dmd2>.\windows\bin\dmd.exe -m64 test.d
test.obj : error LNK2019: unresolved external symbol stderr
referenced in functi
on main
test.exe : fatal error LNK1120: 1 unresolved externals
--- errorlevel 1120
Arch linux x86 compiling for Android x86:
test.o:test.d:function main: error: undefined reference to
'stderr'
The linker seems to find the symbol for stderr on platforms where
it's defined extern in libc. On platforms like Android, with the
following stdio.h and stdio.d, not so much.
Android:
stdio.h:
__BEGIN_DECLS
extern FILE __sF[];
__END_DECLS
--snip--
#define stdin (&__sF[0])
#define stdout (&__sF[1])
#define stderr (&__sF[2])
https://android.googlesource.com/platform/bionic/+/master/libc/include/stdio.h
My stdio.d:
else version( Android )
{
enum
{
_IOFBF = 0,
_IOLBF = 1,
_IONBF = 2,
}
private extern shared FILE[3] __sF;
shared stdin = &__sF[0];
shared stdout = &__sF[1];
shared stderr = &__sF[2];
}
I followed the example of Solaris and Win32, but it appears those
don't work either. My guess is that OS X will work and Solaris
won't, based on these similarities, but I don't have either
accessible to test on. If I call &__sF[2] directly from test.d,
that does work on Android.
So the question is, when one has a #define macro like the above,
how does one create the equivalent symbol in D? It appears that
the authors of druntime are unsure of how to do this also.
More information about the Digitalmars-d
mailing list