Xcode将tensorflow lite库链接到MacOS swift/Objective-C应用程序

zxlwwiss  于 2023-06-24  发布在  Mac
关注(0)|答案(1)|浏览(155)

我目前正在开发一个使用TensorFlow Lite的应用程序。到目前为止,我一直在使用Xcode(Swift + Objective-C)用于iOS版本,C和Python库用于macOS上的UI。但是,我现在也在尝试将macOS版本迁移到Swift/Objective-C应用程序。
我在链接TensorFlow Lite库时遇到问题。我必须指出,我不是编译Maven,特别是Xcode,我认为自己是这个领域的完全初学者。
我试图根据Stack Overflow这篇文章中提供的说明构建一个静态库:How to build TensorFlow Lite C API static library?
不幸的是,我遇到了另一个Stack Overflow问题中概述的问题:TensorFlow静态C API库-如何与10个子依赖项链接?
考虑到这一点,我想也许我应该尝试直接链接共享库,类似于我为C
版本所做的,而不是处理多个依赖项。
我尝试了这篇Stack Overflow文章中描述的方法:Xcode linking against static and dynamic library
但是,由于我试图链接的是一个.so而不是一个.dylib,所以在第二步(嵌入文件,文件没有出现在finder中)被阻塞了
编辑:我已经将tensorflow构建为dylib,并成功通过了第2步,但下面的错误消息保持不变(除了.dylib现在也是)
所以我被这个错误消息卡住了:

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的自引用。
如果任何人有任何关于如何解决这个问题的想法,或者如果我朝着正确的方向前进,您的帮助将不胜感激!

xmakbtuz

xmakbtuz1#

对于那些谁会发现这篇文章。我最终成功地编译了tensorflow lite静态库,并在我的Xcode项目中逐一链接了所有依赖项(静态库)。我只是关注我在问题中链接的帖子:TensorFlow静态C API库-如何与10个子依赖项链接?
在我看来,这不是“最好”的方式,但它的工作。

相关问题