Cross Compile TensorFlow C++ app for the Jetson TK1

Last time I've posted about cross compiling TF for the TK1. That however was a canned sample example from TF, based on the bazel build system.
Let's say we want to make our own TF C++ app and just link vs. TF for inference on the TK1.
Now that's a huge mess.

First we need to cross-compile TF with everything built in.
Then we need protobuf cross-compiled for the TK1.
Bundle everything together, cross(-compile) our fingers and pray.

The prayer doesn't help. But let's see what does...

I've learned a lot from:

Build TF

To make TF run meaningfully, we need to make two libraries: and

Then bazel build it with the CROSSTOOL we created last time:

If you haven't bazel cleaned since last time this step should only take a minute or so.

Build Protobuf

First we need to compile PB for the host. Trust me on this.
TF team has done an excellent job to facilitate this:

Then we move to compiling PB for arm-linux

See what I did there? we needed a working protoc, and we can't use the cross-compiled one since it doesn't run on the host, it's made for arm...

Gather everything for app cross-compilation

I've created a script that takes everything from the TF directory and places it where you need it:

Example app

We'll set up the example app with CMake:

With a very basic TF C++ code from here:

We also need a CMake cross-compilation toolchain file, which I've called arm-linux-gnueabihf.cmake:

Then compile with cmake as per usual, specifying the cross compilation toolchain file

Once it builds, push the executable, libraries, etc. to the TK1

You can also execute it remotely on the TK1, to save a terminal window:

And that's about it - you can now build standalone Tf 1.5+ apps in C++ for the Jetson TK1!