The documentation made this sound easy. Well, as with many things, it wasn’t.

Installing the dependencies

In order to build the tensor flow go bindings we need to use a build tool called bazel. Bazel requires Java 8 so you can’t just install the latest version of java (java 9) to get bazel to work. I tried that and kept getting this output whenever I’d run the ./configure command.

Extracting Bazel installation...
Problem with java installation: couldn't find/access rt.jar in /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home
Traceback (most recent call last):
  File "", line 1036, in <module>
  File "", line 971, in main
  File "", line 444, in check_bazel_version
    curr_version = run_shell(['bazel', '--batch', 'version'])
  File "", line 141, in run_shell
    output = subprocess.check_output(cmd)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 573, in check_output
    raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['bazel', '--batch', 'version']' returned non-zero exit status 1

Turns out Java 9 got rid of the rt.jar (or maybe moved it) and bazel can’t handle that. This has been a known issue for well over a year as of this post. The only fix that I found was to actually install java 8. So I uninstalled java 9 then installed java 8.

$ brew cask uninstall java
$ brew cask install caskroom/versions/java8


Once made bazel was happy I was able to successfully run ./configure and after that bazel build --config opt //

All that stuff went smoothly. I’m not sure if I answered all the questions asked by ./configure correctly, but at least it built.


After a successful build I didn’t really want to copy the file to /usr/local/lib, instead I wanted to just specify it via the test command. I misread the docs, and thought they said to use only the variable DYLD_LIBRARY_PATH so I ran the test command with that.

$ DYLD_LIBRARY_PATH=${GOPATH}/src/ go test

This gave the error output indicating that it wasn’t able to find the library.

ld: library not found for -ltensorflow
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ld: library not found for -ltensorflow
clang: error: linker command failed with exit code 1 (use -v to see invocation)
FAIL [build failed]

Turns out you need to run with both variables LIBRARY_PATH and DYLD_LIBRARY_PATH.


Moral of the story is, read the documentation carefully and sometimes required dependencies have outdated dependencies.