On Wednesday, 24 June 2020 at 12:00:04 UTC, Jacob Carlborg wrote:
On Monday, 22 June 2020 at 14:32:21 UTC, Anton wrote:
I have a static library (.a) compiled with LDC for iOS
platform. But I can't figure out how to correctly connect it
to the project and call its functions. I've already linked
binary with library to the project but IDE still doesn't see
its classes and methods. Do I need to do some additional
configurations?
When you say "IDE", I'm going to assume you're referring to
Xcode. Xcode has absolutely no support for D at all.
Since the Objective-C support in LDC is so limited I would
recommend creating `extern(C)` functions in the D code, which
forwards to your D functions (or have the functions being
`extern(C)` to begin with). Then you need to have these
declarations available in a C header file, either created by
using the `-HC` flag or by manually writing the declarations.
--
/Jacob Carlborg
Thank you! We did it as you said and it works.
And thanks a lot for the iOS support, it's amazing!
Few notes on our finding, maybe it will help someone.
--- About header files:
We had to use DMD to create .h files. Couldn't find a way to get
them via ldc, which seems to only generate .di files (probably
just missing something).
In the end, we are using the compiled D library from Flutter
Dart, writing pointers to symbols manually.
--- About compiling for iOS simulator:
When compiling druntime and phobos for iOS simulator, you need to
add -mios-simulator-version-min=12.0 flag to --cFlags, here is an
example:
ldc-build-runtime --ninja
--cFlags="-mios-simulator-version-min=12.0;-target;x86_64-apple-darwin" --dFlags="-mtriple=x86_64-apple-darwin;-fvisibility=hidden" CMAKE_SYSTEM_NAME=Darwin BUILD_SHARED_LIBS=OFF
(More info: https://wiki.dlang.org/Building_LDC_runtime_libraries)
And you have to link phobos and druntime static libraries (.a)
files to Xcode, not just your library.