On Monday, 25 November 2013 at 11:32:56 UTC, Chris wrote:
On Monday, 25 November 2013 at 10:38:24 UTC, Joakim wrote:
Next step, get dmd to do the same with a "hello world" native
Android app. I'll update this thread as I go, for anyone
who's interested.
Thanks, I'm interested.
I just spent a couple hours trying to get dmd to compile a "hello
world" app on linux/x86 without druntime and phobos, so I might
as well document it here. After looking at a bunch of old
newsgroup posts and some druntime source, I came up with the
following foo.d:
extern (C) void puts(const char*);
extern (C) int main() {puts("Booya cuddie!\n");return 0;}
I compiled foo.d with a local, unpatched build of dmd from git as
of 10 days ago, dmd compiled by clang++:
./src/dmd -v foo.d -betterC -defaultlib=
No good, it wants an object.d, despite being a better C:
Error: cannot find source code for runtime library file 'object.d'
dmd might not be correctly installed. Run 'dmd -man' for
installation instructions.
Specify path to file 'object.d' with -I switch
So I copied object.di from druntime into the same directory, but
it turns out that simply placing an empty file called object.di
there also works. :)
Next error, it doesn't link:
foo.o:(.text.d_dso_init[.data.d_dso_rec]+0x33): undefined
reference to `_d_dso_registry'
collect2: error: ld returned 1 exit status
--- errorlevel 1
So I checked the symbols from the object file it did build:
nm foo.o
00000000 t
U _GLOBAL_OFFSET_TABLE_
U _d_dso_registry
00000000 T main
It turns out that there's a weak reference to _d_dso_registry for
ELF object files, but it was recently made a requirement on linux
only. I got rid of that requirement by changing the
REQUIRE_DSO_REGISTRY define to this line in
./src/backend/elfobj.c:
#define REQUIRE_DSO_REGISTRY (DMDV2 && TARGET_RLINUX)
Recompile dmd and foo.d now builds and runs. :) Obviously, this
patch shouldn't be necessary if you're not on linux.
Next, getting this minimal app running on Android/x86. It turns
out there is some support for building executables directly in
the Android NDK, just undocumented, though the docs are fairly
bad generally.