Skip to content

Commit a52935e

Browse files
update
1 parent aa63ee9 commit a52935e

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

compile_tensorflow_cpp.md

+26-20
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ Building TensorFlow C++ API is very tricky and can be a pain as there is not muc
44

55
On this page, I will walk you through the steps to install **TensorFlow C++ API version 2.7**.
66

7+
- [Compile TensorFlow C++ from source code](#compile-tensorflow-c-from-source-code)
8+
- [Dependencies](#dependencies)
9+
- [Install package dependencies](#install-package-dependencies)
10+
- [1. Environment setup](#1-environment-setup)
11+
- [2. Install Bazel](#2-install-bazel)
12+
- [3. Install Protobuf](#3-install-protobuf)
13+
- [Compile TensorFlow C++ and install libraries](#compile-tensorflow-c-and-install-libraries)
14+
- [1. Compile TensorFlow C++ shared library (with optimization)](#1-compile-tensorflow-c-shared-library-with-optimization)
15+
- [2. Copy required files into a single path for C++ linkage](#2-copy-required-files-into-a-single-path-for-c-linkage)
16+
- [3. Compiling the op library and example code](#3-compiling-the-op-library-and-example-code)
17+
- [Optional: Compile TensorFlow via pip (wheel) builder](#optional-compile-tensorflow-via-pip-wheel-builder)
18+
- [References](#references)
19+
720
## Dependencies
821

922
- Conda
@@ -58,7 +71,17 @@ chmod +x bazel-3.7.2-installer-linux-x86_64.sh
5871

5972
### 3. Install Protobuf
6073

61-
I suggest installing protobuf after building TensorFlow (see below) so that we are able to check that which version of protobuf we should use.
74+
1. Check the version of protobuf that is supported by TensorFlow in the file `tensorflow/workspace2.bzl`,
75+
e.g., TF 2.7.0 supports Protobuf 3.9.2
76+
2. Download protobuf source code from its GitHub release https://github.com/protocolbuffers/protobuf/tags
77+
- E.g. v3.9.2 https://github.com/protocolbuffers/protobuf/releases/tag/v3.9.2
78+
3. Compile and link
79+
```bash
80+
./configure --prefix=/home/rangsiman/protobuf-3.9.2/ CXXFLAGS="-D_GLIBCXX_USE_CXX11_ABI=0"
81+
make
82+
make check
83+
make install
84+
```
6285

6386
---
6487

@@ -165,24 +188,7 @@ pip install /tmp/tensorflow_pkg/tensorflow-2.3.0-cp38-cp38-linux_x86_64.whl
165188
python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
166189
```
167190

168-
### 2. Install protobuf
169-
170-
1. Check the version of protobuf that is supported by TensorFlow
171-
```bash
172-
bazel-bin/external/com_google_protobuf/protoc --version
173-
libprotoc 3.9.2
174-
```
175-
2. Download protobuf source code from its GitHub release https://github.com/protocolbuffers/protobuf/tags
176-
- E.g. v3.9.2 https://github.com/protocolbuffers/protobuf/releases/tag/v3.9.2
177-
4. Compile and link
178-
```bash
179-
./configure --prefix=/home/rangsiman/protobuf-3.9.2/
180-
make
181-
make check
182-
make install
183-
```
184-
185-
### 3. Copy required files into a single path for C++ linkage
191+
### 2. Copy required files into a single path for C++ linkage
186192

187193
```bash
188194
sudo mkdir /usr/local/tensorflow
@@ -193,7 +199,7 @@ sudo cp -r bazel-bin/tensorflow/*.so* /usr/local/tensorflow/lib
193199
sudo cp -r /home/rangsiman/protobuf-3.9.2/lib/*.so* /usr/local/tensorflow/lib
194200
```
195201

196-
### 4. Compiling the op library and example code
202+
### 3. Compiling the op library and example code
197203

198204
**Example-1**: Zero out
199205

0 commit comments

Comments
 (0)