【发布时间】:2018-04-28 03:37:41
【问题描述】:
我正在尝试从 64 位 Ubuntu 17.10 中的 C/C++ 源代码构建 Tensorflow 1.4.0。我尝试使用 Bazel 遵循Tensorflow website 和other website for C++ 中的说明并将它们总结如下:
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
当我尝试构建一个简单的测试程序并在 Eclipse 中包含 tensorflow/core/public/session.h 时(包含路径设置为从 git 下载的 tensorflow 根文件夹),它抱怨几件事:
- device_attributes.pb.h 中缺少 Google 的 protobuf common.h(我无法使用 apt-get 安装 protobuf,因为它会抱怨版本太旧 - 低于 3.0 .0.4 签入 device_attributes.pb.h)。我下载了最新的 protobuf 并按照说明进行安装
- tensor.h 中缺少 Eigen3 的 Tensor 文件,其中 tensor.h 包含 [tensorflow 目录]/third_party/eigen3/unsupported/Eigen/CXX11/Tensor 中的 Tensor 文件 ,而 [tensorflow 目录]/third_party/eigen3/unsupported/Eigen/CXX11/Tensor 包括缺少的 [/usr/include/eigen3/]unsupported/Eigen/CXX11/Tensor > libeigen3-dev 提供的文件。我 apt-get 安装 libeigen3-dev。
- 安装 libeigen3-dev 后,我将 /usr/include/eigen3 添加到 Eclipse 的包含路径中,因为 tensorflow 目录中的 Tensor 文件无法在 /usr 中找到 Tensor 文件/include(带有额外的 eigen3 目录)。
- mutex.h 中缺少 nsync_cv.h 文件。我将 tensorflow 目录中的 nsync 文件夹添加到包含路径中。
综上所述,我在 Eclipse 的包含路径中添加了以下路径:
- [张量流目录]/
- [tensorflow 目录]/bazel-genfiles
- [tensorflow目录]/bazel-tensorflow/external/nsync/public
- /usr/include/eigen3
我在库路径[tensorflow目录]/bazel-bin/tensorflow中添加了以下库:
- 张量流
- tensorflow_cc
- tensorflow_framework
我还在 Eclipse 的项目设置中添加了 -std=c++11 到 GCC C++ 编译器和 GCC C++ Linker。最后它遇到了链接器错误:
[tensorflow directory]/tensorflow/core/platform/default/logging.h:187: undefined reference to `tensorflow::internal::CheckOpMessageBuilder::NewString[abi::cxx11]()'
我看到thread 讨论了类似的问题,但我确实设置了-D_GLIBCXX_USE_CXX11_ABI=0 并且 Ubuntu 17.10 使用的是 gcc5 或更高版本。
请建议如何修复链接器错误。非常感谢!
【问题讨论】:
标签: c++ eclipse c++11 ubuntu tensorflow