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:
- Missing Google's protobuf common.h in device_attributes.pb.h (I cannot use apt-get to install protobuf as it will complain version too old - lower than 3.0.0.4 check in device_attributes.pb.h). I downloaded the latest protobuf and follow the instructions to install it
- Missing Eigen3's Tensor file in tensor.h, where tensor.h includes Tensor file in [tensorflow directory]/third_party/eigen3/unsupported/Eigen/CXX11/Tensor, and [tensorflow directory]/third_party/eigen3/unsupported/Eigen/CXX11/Tensor includes the missing [/usr/include/eigen3/]unsupported/Eigen/CXX11/Tensor file provided by libeigen3-dev. I apt-get to install libeigen3-dev.
- After I installed libeigen3-dev, I added /usr/include/eigen3 to the Eclipse's include path as the Tensor file in tensorflow directory is unable to find the Tensor file in /usr/include (with extra eigen3 directory).
- Missing nsync_cv.h file in mutex.h. I added nsync folder in tensorflow directory to the include path.
In summary, I have added the following paths to the include path in Eclipse:
- [tensorflow directory]/
- [tensorflow directory]/bazel-genfiles
- [tensorflow directory]/bazel-tensorflow/external/nsync/public
- /usr/include/eigen3
I added the library path [tensorflow directory]/bazel-bin/tensorflow with the following libraries:
- tensorflow
- tensorflow_cc
- tensorflow_framework
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!