You should know, that TensorFlow written on C++ as core (backend) and Python as frontend languages.

Python was the first client language supported by TensorFlow and currently supports the most features. More and more of that functionality is being moved into the core of TensorFlow (implemented in C++) and exposed via a C API.

If you are working with TensorFlow not only as Python software engineer, from time to time you should use C++ environment and available code, in your work. Sometimes you need to clarify C API, sometimes use it to port Python available code to other language. Any way you have to have build – ready C++ code on your computer.

How you can prepare it?

You need build it from sources. There is short guide:

I am working on OS X 10.12, so my instruction for that OS version.

Lets start from JDK8. Yes, we need JDK. There is bazel tool which help us to build tensorflow library from sources. Bazel based on Java, so we need JDK. Actually, in my case I had some java virtual machine, but if you don’t go to download page.

Now, it is time to install bazel,  there are two ways:

First:

Second:

GitHub bagel releases page

If you finished with bazel, get tensorflow:

After, install GNU coreutils by issuing the following command:

Xcode also must be installed. Use AppSore for that.

Some steps to configure your build:

 

Build all you need:

Do clean, if you would like to change anything in your configuration:

Also in future you will need more extra sources, for that let’s download:

Result will be stored at that path:

You will need Eigen and unsupported source folders from it.

 

All you needed files will be available by links (will be removed after restart) at tensorflow repository root folder:

That step will save your folder space, if you remove obj files from build folder.

 

To test environment, let’s try build C++ trainer example.

  1. Open Xcode.
  2. Create command line project.
  3. Add headers and library folder to project settings (from bazel builded directory).
  4. Include libtensorflow_cc.so file in project and add it to copy phase.

In my case I needed to restore dynamic library path using command:

Project Settings

Build

Launch

 

Author: Volodymyr Pavliukevych

Senior Software Engineer, Data Scientist.

Senior Software Engineer, Data Scientist.

No Comments so far.

Leave a Reply