Closed fayfive closed 2 years ago
Can you give an example of what exactly you are trying to achieve, how many DLL's you have, header files, etc.
I export LD_LIBRARY_PATH to solve it. That means the *.so must place to the system lib directory. Can dart specify the C lib directory?
I am not sure what you mean.
But all you need to know is that currently ffigen can only bind to a single lib.so
.
If you have multiple .so files, you need to separate the headers and create different config file for each.
I mean, I have two lib, liba and libb, and liba depend on libb, and I have the headers. There is two config.yaml and generated liba.dart and libb.dart. I just call liba's function, "DynamicLibrary.open('${Directory.current.path}/lib/liba.so')" if I "dart run main.dart", it will be error "symbol lookup error: undefined symbol". I should "export LD_LIBRARY_PATH=lib/;dart run main.dart".
I want to know if I build the "main.dart" in a ".exe", Can I specify the .so directory of the app?
I am not sure what you mean by "liba depend on libb". If possible please mention the actual libraries you are using.
I want to know if I build the "main.dart" in a ".exe", Can I specify the .so directory of the app?
If this is your primary question, then I am not aware of this, please try asking a question of StackOverFlow as well in that case.
It's ffmpeg. I bind the function, but when I run "dart run main.dart", it showed that
Invalid argument(s): Failed to load dynamic library '/home/jet/working/da/ffmpeg/libffmpeg/libavformat.so': libavcodec.so.58: cannot open shared object file: No such file or directory
I run the command "export LD_LIBRARY_PATH=libffmpeg/;dart run main.dart". It works well. "libffmpeg/" is the director of the *.so.
My directory structure is that ffmpeg lib .dart libffmpeg .so main.dart
Well I guess here ffmpeg is opening a dynamic library internally, and it's only able to find it when you set LD_LIBRARY_PATH.
So this issue is not really in scope with ffigen. ffigen only deals with generating the bindings for a library, and not how the libraries are loaded.
@mannprerak2
I see.
Any suggestions or Can ffi use *.a?
I am not sure, but I'd suggest to take a look at this if you haven't already https://flutter.dev/docs/development/platform-integration/c-interop#dynamic-vs-static-linking
It's not useful. Because android just support .so. I found that gcc can rpath the .so. What about ffi?
@mannprerak2 Thanks a lot! I solved it with rpath when I compile the .so and I found that flutter automatically redefines .so's path when "flutter build" or "flutter run" but "dart run" will not.
Great 👌
If liba depends on libb, when I call the liba functions, it wiil be error "symbol lookup error: undefined symbol". Becase the liba function calls libb function. Thanks!