2

I'm trying to write a dart binary application and link in C code with it.

I read the documentation and I understand how to do the actually ffi at runtime

final lib = ffi.DynamicLibrary.executable();
final VoidFunc greet = lib.lookup<ffi.NativeFunction<CVoidFunc>>('greet').asFunction();

but I don't understand how to statically link my C Code into the build process because I don't want to have to distribute a binary as well as a separate shared library.

Any advice would be helpful and thanks in advance

Richard Heap
  • 48,344
  • 9
  • 130
  • 112
Adi Mehrotra
  • 150
  • 1
  • 7
  • For any C library that you export for general use you usually have 2 files, a header and a shared object, even tho you could get away with only the shared object – ACoelho Dec 02 '20 at 12:19
  • Are you building with `dart2native`? There doesn't seem to be a way to have that link in additional shared libraries. – Richard Heap Dec 02 '20 at 14:37

1 Answers1

2

Hi give a look at this maybe it will help you solve this problem [dart:ffi][1]

[1]: https://flutter.dev/docs/development/platform-integration/c-interop ,also you are using right the DinamicLibrary , i dont think that it will be helpful but why not you give it a try , chane executable and add process().

gregni
  • 417
  • 3
  • 12
  • This documentation is now located at: https://docs.flutter.dev/development/platform-integration/ios/c-interop#dynamic-vs-static-linking – pasty Oct 18 '22 at 15:59