我在使用 Tensorflow 时遇到了一些问题。我必须将我使用 TF 的代码集成到一个已经存在的项目(使用 Makefile)中。这就是我所做的。
我从源代码中获取了 TF 并按照描述安装了它 on the TF site.
然后我构建了一个共享库:
bazel build //tensorflow:libtensorflow.so
完成此操作后,我将以下行添加到 Makefile:
CFLAGS += -I/home/alpy/tensorflow/bazel-genfiles
CFLAGS += -I/home/alpy/tensorflow/
CFLAGS += -I/home/alpy/tensorflow/third_party/eigen3
LDFLAGS += -L/home/alpy/tensorflow/bazel-bin/tensorflow
LDFLAGS += -ltensorflow
当我尝试做到这一点时,我得到了这个奇妙的错误:link
编辑:我忘了解释一些东西。我在 Linux 上,所以编译器应该区分大小写。我检查了我的文件和 TF 文件,它们似乎都有#ifndef 保护。
编辑:按照我的建议,我将错误直接添加到帖子中:
In file included from /home/alpy/tensorflow/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1:0,
from /home/alpy/tensorflow/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1,
from /home/alpy/tensorflow/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1,
from /home/alpy/tensorflow/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1,
from /home/alpy/tensorflow/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1,
from /home/alpy/tensorflow/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1,
from /home/alpy/tensorflow/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1,
from /home/alpy/tensorflow/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1,
from /home/alpy/tensorflow/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1,
[...]
from /home/alpy/tensorflow/tensorflow/core/public/session.h:23,
from ../src/conversion.h:11,
from ../src/detect_fast_C.cpp:43:
/home/alpy/tensorflow/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1:42: error: #include nested too deeply
In file included from /home/alpy/tensorflow/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1:0,
from /home/alpy/tensorflow/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1,
from /home/alpy/tensorflow/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1,
from /home/alpy/tensorflow/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1,
from /home/alpy/tensorflow/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1,
[...]
from /home/alpy/tensorflow/tensorflow/core/framework/types.h:23,
from /home/alpy/tensorflow/tensorflow/core/framework/type_traits.h:22,
from /home/alpy/tensorflow/tensorflow/core/framework/allocator.h:25,
from /home/alpy/tensorflow/tensorflow/core/framework/tensor.h:21,
from /home/alpy/tensorflow/tensorflow/core/public/session.h:23,
from ../src/conversion.h:11,
from ../src/detect_fast_C.cpp:43:
/home/alpy/tensorflow/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1:42: error: #include nested too deeply
(这会持续一段时间)
最佳答案
我认为你不应该添加所有这些 - 我包括
您可以查看 bazel 构建系统中的引用 C++ 示例。
cc_二进制文件。 https://github.com/tensorflow/tensorflow/blob/master/tensorflow/cc/BUILD#L264
旗帜: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tensorflow.bzl#L111
您可以使用 -s
选项运行 bazel build 以查看为构建目标发出的实际命令。
关于c++ - 尝试使用 tensorflow 的 C++ API 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39211898/