D
D
dasannikov2013-12-02 14:54:48
iOS
dasannikov, 2013-12-02 14:54:48

Is it possible to embed D modules in Xcode and iOS apps?

Is it possible to embed modules in D in XCode and iOS applications (Either to compile or at the level of .so/.obj files). If yes, tell me which pipeline.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Monnoroch, 2013-12-02
@dasannikov

Theoretically, D compiles into object files, which, among other things, can export symbols with extern "C", that is, those that can be called from C (Obj-C). It remains only to link Obj-C objects and D objects with a linker that can do both: for example, gcc is suitable for this (I myself linked c ++ and D objects together). As far as I remember, clang is used in xcode, but it is quite possible that he can too, check.
You just need to separately compile .d files using, for example, digital mars compiler, generate .h files for extern "C" functions to include them in Obj-C, and add those objects that the D compiler generated to the linked objects.
With C++ (gcc 4.7, linux) it's definitely possible, it didn't work for me on Windows.
The only thing is, if your main is not on D, then there may be a problem with Druntime, which must be initialized for the garbage collector to work correctly.
An interesting fact: if you do not use GC memory, then even runtime initialization is not needed (I don’t know how in theory, but it worked for me).
In general, to be honest, I would say that it is much easier to write a program in D with C or Obj-C plug-ins (here you have to deal with auto-release pools) modules in the form of static or dynamic libraries.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question