-
Notifications
You must be signed in to change notification settings - Fork 32
Problem adding C dynamic library to existing flutter application. #109
Comments
With static libraries you need to tell the Xcode linker to not strip the symbols. s.vendored_libraries = 'Frameworks/libmylib_staticlib.a'
s.pod_target_xcconfig = { "OTHER_LDFLAGS" => "-force_load $(PODS_TARGET_SRCROOT)/Frameworks/libmylib_staticlib.a" } The Static libraries are linked in to the executable, so you don't |
Thanks a lot for your response! I made those changes:
s.vendored_libraries = 'Frameworks/lib.a'
s.pod_target_xcconfig = { "OTHER_LDFLAGS" => "-force_load $(PODS_TARGET_SRCROOT)/Frameworks/lib.a" }
If I launch application using those lines: final DynamicLibrary dynamicGoLibrary = DynamicLibrary.open('lib.a'); or final DynamicLibrary dynamicGoLibrary = DynamicLibrary.open('Frameworks/lib.a'); I get following exception: ArgumentError (Invalid argument(s): Failed to load dynamic library 'lib.a': dlopen(lib.a, 1): image not found) If I try to launch it using final DynamicLibrary dynamicGoLibrary = DynamicLibrary.executable(); I get following error: ArgumentError (Invalid argument(s): Failed to lookup symbol (dlsym(RTLD_DEFAULT, Keys): symbol not found)) This library was build from cgo using c-shared mod. When I try to call it from dart using |
Because of the way Flutter plugins are set up (they generate a ton of boilerplate files from a templating system for every target platform), it is not recommended to try to create this boilerplate in an existing application. Instead, create a Flutter FFI plugin and the application in the same Git repo. Here is a PR adding FFI plugins to Flutter. (Instructions to on how to run it in the PR for if you want to use this before its merged.) For using Golang, please make sure that an example with C code works before using Go. That way we ensure the issue is in the Go setup rather than in the rest of the setup. Feel free to open a new issue w.r.t. Go. (Closing this one as its title is asking for an unsupported use case.) |
Would be really useful having some sort of guide how to do this on macOS and iOS properly, having to write a CocoaPods file is just a world of pain if you don't have any idea how to do it, even the linter will fail with C++ headers if you don't know the magic --skip-import-validation flag which I found no reference anywhere. I might write a blog post about this, got pretty pissed while trying to do this, luckily I found this issue and your response @dcharkes ! 🙏 |
Hello!
I've ran into problem trying to add my own small c library to existing flutter application.
Here is error message:
Library is working fine, when I call it directly from dart code on local machine, but when I try to add it to existing flutter project on iOS emulator or iOS device, it throws an error.
Here is 'C interop' official documentation:
Asking to make this step clear:
How to properly add source files to existing project in Xcode? (I have 2 files
lib.a
andlib.h
, which I want to add)I was trying to create a plugin and modify
.podspec
file in different ways, but it doesn't really help. Dart still throwing that error:Here is how my iOS folder structure (in plugin directory):
Here is full
crypto_export.podspec
file:I was trying to call my
lib.a
with following lines:,it doesn't help.
How do I transfer my
lib.a
andlib.h
files from plugin folder to iOS application and how do I open them with dart FFI?Here is link to my GitHub plugin page. All C sources are there, including my c library (simple export of some cryptography functions).
I also tried to modify
.podspec
file adding those lines:And changing this line:
But I still get the same error message, error says, dart can't find a file called
lib.a
. How do I add this file to flutter application on real device?The text was updated successfully, but these errors were encountered: