iOS: Failed to lookup symbol (dlsym(RTLD_DEFAULT, ***)

自从做了 Flutter 调用 rust 代码,xcode 的更新过程中遇到很多次这个问题了,记性不好,每次都是重新去解决,现在记录下来。

Invalid argument(s): Failed to lookup symbol (dlsym(RTLD_DEFAULT, store_dart_post_cobject): symbol not found)

静态链接库引入

首先确定你的静态链接库 .a 正确的引入到了项目中,你使用的 plugin 的 .podspec 文件中定义了静态链接库的位置

s.public_header_files = 'Classes**/*.h'
s.source_files = 'Classes/**/*'
s.static_framework = true
s.vendored_libraries = "**/*.a"

在你的 plugin 的 .podspec 文件或者 main app 的 Build Settings 中应当将静态链接库配置到 ldflag,比如 libmylib.a就是-lmylib

'OTHER_LDFLAGS' => '-lmylib'

防止被编译器清理

在 Xcode 中打开项目,点开 Runner -> Build Settings 搜索 “Strip” 找到以下两项

  • Strip Style::改为 Non-Global Symbols 去除非全局符号但保存外部符号。
  • Dead Code Striping:改为 No 防止 xcode 检测不到未在 Swift 代码中使用的 symbol。

参考链接:

Flutter Release 测试 (Archive)

flutter run -d iPhone --release

Comments