0

I'm trying to run a hello world macOS project that runs Tensorflow models. Documentation for Tensorflow (not to be confused by Tensorflow Lite) lack instructions on how to add the libtensorflow_framework to an XCode project that targets macOS.

What I did so far is:

  1. create a conda environment (pip, python3.8.3)
  2. pip install tensorflow==2.3.0rc0
  3. locate the path to the tensorflow package, and drag and drop the libtensorflow_framework.2.3.0.dylib file into a group called lib that is located directly under the project root.

The I tried to run the app, but I got the following error:

ld: library not found for -ltensorflow_framework.2.3.0
clang: error: linker command failed with exit code 1 (use -v to see invocation)

which doesn't even make sense, because the file name is libtensorflow_framework.2.3.0.dylib and not ltensorflow_framework.2.3.0

Emad Omar
  • 729
  • 9
  • 23
  • 1
    The linker usually prefixes with lib and suffixes with either dylib or lib, so if it only says `library not found for -ltensorflow_framework.2.3.0`, the message makes sense if it cannot find `libtensorflow_framework.2.3.0.dylib`. Can you check in xcode if the linker is searching in the path where you put `libtensorflow`? https://blogs.wcode.org/2014/11/howto-setup-xcode-6-1-to-work-with-opencv-libraries/ should help. – Mikael H Jun 28 '20 at 15:56
  • @MikaelH thanks, I looked into that link, added the library and header search paths and now the app builds successfully. However, I'm presented with another error now `dyld: Library not loaded: @rpath/libtensorflow_framework.2.dylib Referenced from: /Users/myname/Library/Developer/Xcode/DerivedData/myproject-aydwnfuhwpganbawdedqbnxoakik/Build/Products/Debug/myproject.app/Contents/MacOS/myproject Reason: image not found` – Emad Omar Jun 28 '20 at 16:47
  • Hm, I don't know (I don't use Mac nor do I use xcode or tensorflow). I would guess that the error is rather searchable. Do you find some useful info here? https://stackoverflow.com/questions/17703510/dyld-library-not-loaded-reason-image-not-found. – Mikael H Jun 28 '20 at 17:12
  • @MikaelH I understand. I appreciate you looking into this. I actually finally solved the loading issue by downloading through Homebrew using this answer https://stackoverflow.com/a/57937424/4112200 and then making sure the dylib and header files are reachable. Now, I get this error trying to print the TensorFlow version `Undefined symbols for architecture x86_64: "_TF_Version", referenced from:`. Do you happen to know if this means I should build TensorFlow from source? – Emad Omar Jun 28 '20 at 17:17
  • It seems the library is not correctly linked to the project that is using it. You should not necessarily need to build it, but it's a bit hard to know with this info. Maybe check here and see if it solves it? https://stackoverflow.com/questions/18408531/xcode-build-failure-undefined-symbols-for-architecture-x86-64 – Mikael H Jun 28 '20 at 17:41

1 Answers1

0

So, I'm not sure what was the cause of that problem. However, I was able to finally link Tensorflow 2.2.0 to my Xcode project. (thanks to the hints that @Mikael H provided)

Here's what I did:

  1. I installed TensorFlow using brew instead of python/pip.
brew install libtensorflow
  1. I checked that /usr/local/include has the ./tensorflow/ headers and I added this path to the Xcode Header Search Path.
  2. I checked that /usr/local/lib has the dylib files and added the path to Library Search Path.
  3. I added the following arguments -ltensorflow -ltensorflow_framework.2.2.0 to the Other Linker Arguments.

You can find the Header Search Path, Library Search Path, and Other Linker Arguments by going to your target's settings -> Build Settings -> All & Combined.

Emad Omar
  • 729
  • 9
  • 23