Use this tag for questions about Dart's Foreign Function Interface (FFI) - the ability to call C directly from Dart. It is equally applicable to applications running in the Dart VM and to Flutter applications (except Flutter Web, of course).
Questions tagged [dart-ffi]
109 questions
2
votes
0 answers
How to include files in dart package
I've a package which ships with some lib's(*.so and *.dll), when i try accessing them from my a project, it always returns no such file or directory.
I think whenever a plugin is being used, the working directory is pointing at the directory of…

Frank nike
- 330
- 5
- 12
2
votes
1 answer
How to run a c statically linked library (.a archive) in flutter?
I'm trying to include a C library in my flutter app.
I have some .h files, and a .a file.
If I understand correctly, the .h files are headers, and the .a file is a statically linked library.
My goal is to run some functions from that library into my…

Manu
- 372
- 2
- 12
2
votes
1 answer
array members of structs in dart:ffi
I'd like to use Bob Jenkins rng in my flutter projects
https://burtleburtle.net/bob/rand/isaacafa.html
here we have a struct with 2 static buffers in it
/* context of random number generator */
struct randctx
{
ub4 randcnt;
ub4…

Producer
- 68
- 7
2
votes
1 answer
How to statically link C code with Dart code to enable ffi with the dart ffi library
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 =…

Adi Mehrotra
- 150
- 1
- 7
2
votes
1 answer
Accessing assets from C++ plugin through Flutter
I'm trying to use Google Oboe for a 3D audio processing app due to it's low latency. The app will have a C++ backend, which does the processing, and the frontend is done with Flutter. I'm running a couple of tests to see if it'll work but I'm having…

Facundo Farall
- 500
- 6
- 18
1
vote
0 answers
How to pass struct and function between golang and dart?
i,m trying to use a Golang service in flutter app with using ffi library [https://pub.dev/packages/ffi], but i have a problem to send struct from go and use in flutter ... ( i can use GetKey & SumNumber func in dart but when i used struct show me…

Masoud
- 33
- 5
1
vote
0 answers
How to add dlib in a flutter iOS plugin using dart:ffi?
I'm new to flutter development and I'm trying to develop a plugin that uses dlib through dart:ffi. I was able to build the dlib and generate libdlib.a but I can't add it to my podspec.
My podspec looks like this:
Pod::Spec.new do |s|
s.name …

Júlio Macedo
- 11
- 1
1
vote
1 answer
Problem Getting Float Pointer and Int from Native C to Dart
I have a basic FFI call that retrieves a C struct from Dart. Only the char * and int * fields of the struct are returning proper values. The float * and int are returning the wrong values. The C and Dart code is below along with the output.
If I…

Kdigital
- 3,795
- 3
- 28
- 24
1
vote
0 answers
Flutter FFI creating new threads automatically for native code
I have a app running 2 isolates - the main and a processing isolate (lets' call it decoder). The processing isolates receives messages from the main threads and also send data for some processing on main thread. Of course these communications are…

banerjk
- 335
- 2
- 15
1
vote
0 answers
Get the SendPort of a named ReceivePort without direct access to the ReceivePort for testing?
I am unit testing and trying to mock a class calling C functions through ffi.
A pair of functions is responsible for starting and stopping a thread in C.
The start function passes a nativePort to C to communicate with the thread.
The stop function…

fdollack
- 31
- 4
1
vote
1 answer
How to create a shared library in android and use it in flutter?
TL;DR
I have this C function in meaning_of_life.c:
#define FFI_PLUGIN_EXPORT
FFI_PLUGIN_EXPORT int getMeaningOfLife(){
return 42;
}
I tried to compile it to a shared library (.so) using alot of ways but I keep getting errors when I try to use…

HII
- 3,420
- 1
- 14
- 35
1
vote
0 answers
How Can I Call Function From Object in dart:ffi (C++) .so file
This is the code inside my .so file.
RustGreetings g = new RustGreetings();
String r ;
try{
**r = g.sayHello("world");**
Log.d("tests","----------------"+r);
} catch (Exception ex){
Log.e("JNI","--------"+ex.getMessage());
}
I want to…

C ivit Vaghani
- 19
- 2
1
vote
1 answer
Reading png using dart ffi and libpng
I am trying to use libpng1.6 to load a png from file, but the execution fails with a segmentation fault.
I load the library and libpng function called png_image_begin_read_from_file as shown:
final dylib = ffi.DynamicLibrary.open(
…

abyesilyurt
- 399
- 3
- 13
1
vote
1 answer
Flutter C++ bindings with dart::ffi
I am trying to write a wrapper package for a C++ code that does some data analyses in our App.
I found this great post that shows the major steps needed to do that. I am more a C/C++ coder so I am a bit stuck and I don't get what I am doing…

PMDP3
- 35
- 7
1
vote
1 answer
Dart/Flutter FFI: Convert List to Array
I have a struct that receives an array of type Float from a C++ library.
class MyStruct extends Struct{
@Array.multi([12])
external Array states;
}
I am able to receive data and parse it in Dart.
Now I want to do the reverse. I…

Sanjay
- 315
- 3
- 15