1 # TensorFlow Lite for iOS 2 3 ## Building 4 5 To create a universal iOS library for TensorFlow Lite, you need to build it 6 using Xcode's command line tools on a MacOS machine. If you have not already, 7 you will need to install Xcode 8 or later and the tools using `xcode-select`: 8 9 ```bash 10 xcode-select --install 11 ``` 12 13 If this is a new install, you will need to run XCode once to agree to the 14 license before continuing. 15 16 (You will also need to have [Homebrew](http://brew.sh/) installed.) 17 18 Then install 19 [automake](https://en.wikipedia.org/wiki/Automake)/[libtool](https://en.wikipedia.org/wiki/GNU_Libtool): 20 21 ```bash 22 brew install automake 23 brew install libtool 24 ``` 25 26 Then you need to run a shell script to download the dependencies you need: 27 28 ```bash 29 tensorflow/contrib/lite/download_dependencies.sh 30 ``` 31 32 This will fetch copies of libraries and data from the web and install them in 33 `tensorflow/contrib/lite/downloads`. 34 35 With all of the dependencies set up, you can now build the library for all five 36 supported architectures on iOS: 37 38 ```bash 39 tensorflow/contrib/lite/build_ios_universal_lib.sh 40 ``` 41 42 Under the hood this uses a makefile in `tensorflow/contrib/lite` to build the 43 different versions of the library, followed by a call to `lipo` to bundle them 44 into a universal file containing armv7, armv7s, arm64, i386, and x86_64 45 architectures. The resulting library is in 46 `tensorflow/contrib/lite/gen/lib/libtensorflow-lite.a`. 47 48 If you get an error such as `no such file or directory: 'x86_64'` when running 49 `build_ios_universal_lib.sh`: open Xcode > Preferences > Locations, and ensure 50 a value is selected in the "Command Line Tools" dropdown. 51 52 ## Using in your own application 53 54 You'll need to update various settings in your app to link against TensorFlow 55 Lite. You can view them in the example project at 56 `tensorflow/contrib/lite/examples/ios/simple/simple.xcodeproj` but here's a full 57 rundown: 58 59 - You'll need to add the library at 60 `tensorflow/contrib/lite/gen/lib/libtensorflow-lite.a` to your linking build 61 stage, and in Search Paths add `tensorflow/contrib/lite/gen/lib` to the 62 Library Search Paths setting. 63 64 - The _Header Search_ paths needs to contain: 65 66 - the root folder of tensorflow, 67 - `tensorflow/contrib/lite/downloads` 68 - `tensorflow/contrib/lite/downloads/flatbuffers/include` 69 70 - C++11 support (or later) should be enabled by setting `C++ Language Dialect` 71 to `GNU++11` (or `GNU++14`), and `C++ Standard Library` to `libc++`. 72