Flutter 在 iOS 上使用 rust 构建的静态库报错 symbol not found

16 天前
 musi

Flutter 使用 rust 构建的 test.a 和 test.so 静态库,同样一个方法,在安卓模拟器上可以,在 iOS 模拟器上报 “Failed to lookup symbol: dlsym(RTLD_DEFAULT, rust_dump_file): symbol not found”

已经在 xcode 上配置了 Link Binary with Librarys 和 strip style 和 dead code stripping

if (Platform.isAndroid) {
    try {
	    _lib = DynamicLibrary.open('test.so');
    } catch (e) {
        print('Error: $e');
        rethrow;
    }
} else if (Platform.isIOS) {
    _lib = DynamicLibrary.process();
} else {
    throw UnsupportedError('Unsupported platform');
}

final void Function(Pointer<Utf8>) test = _lib
      .lookup<NativeFunction<Void Function(Pointer<Utf8>)>>("test")
      .asFunction();
805 次点击
所在节点    程序员
14 条回复
iOCZS
16 天前
静态库架构对吗? ARM 模拟器需要 ARM 静态库,另外 debug 不会对静态库进行裁剪,应该都会包含进去。
musi
16 天前
@iOCZS #1 架构是对的,实际上我 arm 和 x86 的都试过
passon
16 天前
General -> Frameworks, Libraries, and Embedded Content 里面添加 .a 库了吗
musi
16 天前
@passon #3 已经添加过了,还是一样的问题
suyulingxm
16 天前
编译时,没有链接上,检查一下配置。
passon
16 天前
之前公司要搞这个费了我不少时间
passon
16 天前
保证静态库不会被裁剪:
在 AppDelegate 里面加上 public func dummyMethodToEnforceBundling() { 里面实现所有要用到的静态库函数,
passon
16 天前
静态库的头文件也要导入
passon
16 天前
Copy Bundle Resources 也加上静态库
passon
16 天前
Build Phases -> Compile Sources 这里面要有静态库的头文件
iOCZS
16 天前
静态库符号不存在,就是.o 没有被编译进去。一般 release 不会包含没被引用到的符号,debug 好像为了提高编译速度,会全量打包进去。
musi
16 天前
感谢各位大佬,等我明天试试再来反馈
naiba
16 天前
https://lifelonglearn.ing/ios-failed-to-lookup-symbol 试试
musi
15 天前
@passon #7 这里的“实现所有要用到的静态库函数”是什么意思?
我有一个 test 函数我好像没办法直接在这里使用

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://tanronggui.xyz/t/1107365

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX