Install Bazel first if you have not installed.
Use Git to clone the TensorFlow repository:
$ git clone https://github.com/tensorflow/tensorflow.git
$ cd tensorflow
The repo defaults to the master development branch. You can also checkout a release branch to build:
$ git checkout branch_name # r1.9, r1.10, etc.
To test your copy of the source tree, run the following test (this may take a while):
$ bazel test -c opt -- //tensorflow/... -//tensorflow/compiler/... -//tensorflow/contrib/lite/...
Configure your system build by running the following at the root of your TensorFlow source tree:
$ ./configure
This script prompts you for the location of TensorFlow dependencies and asks for additional build configuration options (compiler flags, for example)
Call for the build process. Include the 'monolithic' option to avoid the interaction errors between tensorflow and opencv.
$ bazel build --config=opt --config=monolithic //tensorflow:libtensorflow_cc.so
Sources: Official site: https://www.tensorflow.org/install/source StackOverflow: https://stackoverflow.com/a/49764888/1407528