Xcode 将 tensorflow flite 共享库 (.so) 链接到 MacOS swift/Objective-C App

问题描述 投票:0回答:0

我目前正在开发一款使用 TensorFlow Lite 的应用程序。到目前为止,我一直在为 iOS 版本使用 Xcode(Swift + Objective-C),为 macOS 上的 UI 使用带有 Python 库的 C++。但是,我现在正尝试将 macOS 版本也迁移到 Swift/Objective-C 应用程序。

我在链接 TensorFlow Lite 库时遇到问题。我必须指出,我不是编译方面的专家,尤其是 Xcode,我认为自己是该领域的初学者。

我试图根据这篇 Stack Overflow 帖子中提供的说明构建静态库: 如何构建TensorFlow Lite C API静态库?

不幸的是,我遇到了另一个 Stack Overflow 问题中概述的问题: TensorFlow静态C API库——如何链接10个子依赖?

考虑到这一点,我想也许我应该尝试直接链接共享库,类似于我为 C++ 版本所做的,而不是处理多个依赖项。

我尝试了这篇 Stack Overflow 帖子中描述的方法: Xcode 链接静态和动态库

但是因为我试图链接 .so 而不是 .dylib,所以我在第二步被阻止了(嵌入文件,文件没有出现在 finder 中)

所以我被这个错误信息困住了:

dyld[31578]: Library not loaded: @rpath/libtensorflowlite.so
  Referenced from: <B747542F-7B2F-37D7-82A9-1BDB1E9C13D0> /Users/val/Library/Developer/Xcode/DerivedData/MyApp-fssgyguqotwbodfhfxrzdhmwlqao/Build/Products/Debug/MyApp.app/Contents/MacOS/MyApp
  Reason: tried: '/Users/val/Library/Developer/Xcode/DerivedData/MyApp-fssgyguqotwbodfhfxrzdhmwlqao/Build/Products/Debug/libtensorflowlite.so' (no such file), '/usr/lib/system/introspection/libtensorflowlite.so' (no such file, not in dyld cache), '/Users/val/Library/Developer/Xcode/DerivedData/MyApp-fssgyguqotwbodfhfxrzdhmwlqao/Build/Products/Debug/MyApp.app/Contents/MacOS/Frameworks/libtensorflowlite.so' (no such file), '../tensorflow/bazel-out/darwin_arm64-opt/bin/tensorflow/lite/libtensorflowlite.so' (no such file), '/Users/val/Library/Developer/Xcode/DerivedData/MyApp-fssgyguqotwbodfhfxrzdhmwlqao/Build/Products/Debug/MyApp.app/Contents/MacOS/Frameworks/libtensorflowlite.so' (no such file), '../tensorflow/bazel-out/darwin_arm64-opt/bin/tensorflow/lite/libtensorflowlite.so' (no such file), '/System/Volumes/Preboot/Cryptexes/OS@rpath/libtensorflowlite.so' (no such file), '/Users/val/Library/Developer/Xcode/DerivedData/MyApp-fssgyguqotwbodfhfxrzdhmwlqao/Build/Products/Debug/MyApp.app/Contents/MacOS/Frameworks/libtensorflowlite.so' (no such file), '../tensorflow/bazel-out/darwin_arm64-opt/bin/tensorflow/lite/libtensorflowlite.so' (no such file), '/Users/val/Library/Developer/Xcode/DerivedData/MyApp-fssgyguqotwbodfhfxrzdhmwlqao/Build/Products/Debug/MyApp.app/Contents/MacOS/Frameworks/libtensorflowlite.so' (no such file), '../tensorflow/bazel-out/darwin_arm64-opt/bin/tensorflow/lite/libtensorflowlite.so' (no such file), '/usr/local/lib/libtensorflowlite.so' (no such file), '/usr/lib/libtensorflowlite.so' (no such file, not in dyld cache)

为了进一步调查,我运行了命令

otool -L libtensorflowlite.so
来检查任何依赖项。这是 otool 的输出:

../tensorflow/bazel-out/darwin_arm64-opt/bin/tensorflow/lite/libtensorflowlite.so:
    @rpath/libtensorflowlite.so (compatibility version 0.0.0, current version 0.0.0)
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1500.65.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.100.3)
    /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1971.0.0)
    /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)

从输出来看,问题似乎出在libtensorflowlite.so的自引用上。

如果有人对如何解决这个问题有任何想法,或者如果我正朝着正确的方向前进,将不胜感激您的帮助!

xcode macos compilation shared-libraries tensorflow-lite
© www.soinside.com 2019 - 2024. All rights reserved.