0

I'm currently developing an app that utilizes TensorFlow Lite. Up until now, I have been using Xcode (Swift + Objective-C) for the iOS version and C++ with a Python library for the UI on macOS. However, I'm now attempting to migrate the macOS version to a Swift/Objective-C app as well.

I'm encountering an issue with linking the TensorFlow Lite library. I must mention that I am not an expert in compilation, particularly with Xcode, and I consider myself a complete beginner in this field.

I attempted to build a static library based on the instructions provided in this Stack Overflow post: How to build TensorFlow Lite C API static library?

Unfortunately, I encountered an issue outlined in another Stack Overflow question: TensorFlow static C API library - how to link with 10 sub-dependencies?

Considering this, I thought maybe I should try linking the shared library directly, similar to what I did for the C++ version, rather than dealing with multiple dependencies.

I attempted the approach described in this Stack Overflow post: Xcode linking against static and dynamic library

But since I'm trying to link a .so and not a .dylib I'm blocked at the second step (embedding the file, the file is not appearing in finder)

Edit: I've build tensorflow as a dylib and managed to pass step 2 but the error message below remains the same (except .so is .dylib now)

So I'm stuck at this error message:

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)

To investigate further, I ran the command otool -L libtensorflowlite.so to check for any dependencies. Here is the output from 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)

Based on the output, it seems that the problem probably comes from the self-reference made by libtensorflowlite.so.

If anyone has any ideas on how to solve this problem or if I'm heading in the right direction, your help would be greatly appreciated!

Nnevalti
  • 16
  • 3

1 Answers1

0

For those who would find this post. I finally succeeded by compiling tensorflow lite static library and by linking all the dependencies (static lib) one by one in my Xcode project. I just followed the post I linked in my question: TensorFlow static C API library - how to link with 10 sub-dependencies?

In my opinion it's not the "best" way to do it, but it works.

Nnevalti
  • 16
  • 3