Reputation: 708
I am trying to build Tensorflow 1.4.0 from sources for C/C++ in 64-bit Ubuntu 17.10. I tried to follow the instructions in Tensorflow website and other website for C++ using Bazel and summarize them as follows:
cd tensorflow
./configure
(select N for all the options)
bazel build --config=opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --local_resources 2048,.5,1.0 //tensorflow:libtensorflow_cc.so //tensorflow:libtensorflow_framework.so //tensorflow/tools/pip_package:build_pip_package
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
sudo -H pip3 install /tmp/tensorflow_pkg/tensorflow-1.4.0rc1-cp36-cp36m-linux_x86_64.whl
When I tried to build a simple test program and include tensorflow/core/public/session.h in Eclipse (with the include path set to the tensorflow root folder downloaded from git), it complained several things:
In summary, I have added the following paths to the include path in Eclipse:
I added the library path [tensorflow directory]/bazel-bin/tensorflow with the following libraries:
I have also added -std=c++11 to the GCC C++ compiler and GCC C++ Linker in the Eclipse's project settings. In the end it encountered a linker error:
[tensorflow directory]/tensorflow/core/platform/default/logging.h:187: undefined reference to `tensorflow::internal::CheckOpMessageBuilder::NewString[abi::cxx11]()'
I have seen a thread discussing similar issue but I did set -D_GLIBCXX_USE_CXX11_ABI=0
and Ubuntu 17.10 is using gcc5 or above.
Please kindly suggest how to fix the linker error. Many thanks!
Upvotes: 1
Views: 1334
Reputation: 350
If you don't want to tinker with your environment too much there are two unofficial alternatives. One is to compile the C++ API with Floop's tensorflow_cc project and install on your system. The other possibility is to install one of the releases of my packaging project for C and C++ API of Tensorflow. Both projects use CMake (instead of Bazel) to support C++ compilation of your source files.
From Tensorflow point of view, the advantage of tensorflow_cc that you can build GPU support if you want while my project can only use CPU for inference.
Upvotes: 1
Reputation: 124
Officially, you have to create your C++ project in tensorflow sourcetree, write BUILD file and compile it using bazel. Look at this.
I wrote a blog post: https://tuanphuc.github.io/standalone-tensorflow-cpp/ giving detailed instructions to make a standalone C++ Tensorflow with configuration:
- Ubuntu 17.10
- gcc 7.2.0
- tensorflow 1.4.0
- Python 2 or 3
- cmake 3.9.6
- Eigen 3.3.4
- Protobuf (master branch)
- Googletest (master branch)
- bazel
Hope it helps
References:
Packaged TensorFlow C++ library for bazel-independent use
Upvotes: 1