Open jtdLab opened 1 year ago
Static libraries are not currently supported.
dart:ffi
only provides capabilities to do lookups in dynamic libraries or the current executable.
For static libraries to work, either the Dart code itself would need to be compiled to a static library and then the two static libraries would need to be linked together with the native linker (tracked in https://github.com/dart-lang/sdk/issues/49418), or the static library would need to be compiled into a dynamic library specifying the list of symbols that should be visible for lookup. The latter option becomes useful if we could automate that based on which @Native
s are used in a Dart program. But until we have either of those, one should compile to dynamic libraries rather than static libraries.
@dcharkes Thanks for the response. Is it somehow possible to compile the static libs mentioned above into a dynamic lib given a header file? If static libs are not yet supported with ffi is it possible to use them via method channels?
Is it somehow possible to compile the static libs mentioned above into a dynamic lib given a header file?
Yes, if you invoke the linker with the right flags. But why do you have a static library in the first place? Can't you get a dynamic library instead? (Static libraries are usually not stable as a distribution format.) Can you elaborate on your use case?
If static libs are not yet supported with ffi is it possible to use them via method channels?
I don't know the answer to this.
@dcharkes Yeah ;( its closed third party software they only provide a static lib currently (I requested a dynamic one but pending)
I want to include the static libs into an ios version of a flutter plugin following this (see iOS section) to bind to the lib but i run into symbol not found error. If i understand you right, first the static lib has to be compiled to a dynamic one using something like this after that i redo the steps from the first article using the new dynamic lib.
When trying the steps you mentioned here i run into many Error (Xcode): Undefined symbol:
Steps:
Create flutter plugin
Copy the mentioned libcool.xcframework
to ios/Frameworks
Modify .podspec
of the flutter plugin so it contains:
s.vendored_frameworks = 'Frameworks/libcool.xcframework'
s.pod_target_xcconfig = { "OTHER_LDFLAGS" => "-all_load -ObjC" }
Hello, anything new? I have same situation in dynamic libraries with xcframework.
I have same situation in dynamic libraries with xcframework.
This issue is about static libraries, not dynamic libraries. Please file a new issue.
@jtdLab I got duplicate symbols
duplicate symbol '_OBJC_IVAR_$_OBJCImageRef.ptr' in:
/Users/user/Desktop/o/example/ios/Build/Products/Debug-iphonesimulator/o/libo.a[arm64][3](o_image.o)
/Users/user/Desktop/o/example/ios/Build/Products/Debug-iphonesimulator/XCFrameworkIntermediates/o/ok/libo-ios.a[arm64][1075](o_image.mm.obj)
Given the
libcool.xcframework
containing large static binaries like so:and a
bindings.dart
containing the bindings generated with ffigen.What is the recommended way to use this in my iOS FFI Plugin.
My plugins
podspec
looks like this:When opening the dynamic library of the plugin in dart with
DynamicLibrary.open('my_plugin.framework/my_plugin')
and calling one of the bindings i run intoInvalid argument(s): Failed to lookup symbol '<lib_cool_method_a>': dlsym(0x7f97b7a3ecb0, lib_cool_method_a): symbol not found