c++ - 尝试使用 tensorflow 的 C++ API 时出错

标签 c++ makefile tensorflow bazel

我在使用 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/

相关文章:

c++ - Boost::Beast:带有 websocket 流水线的服务器

c++ - 在 QT5 中我需要创建至少 20 个 QThread

c++ - cin >> x 错误时的计算结果是什么?

c++ - 错误 : no matching member function for call to 'reset' (shared pointers)

python - 尝试重用 RNN 权重时出错

php - 我可以更改子类中任何父函数的访问修饰符吗?

c - 递归获取obj文件进行链接

c++ - 如何为使用线性代数 C++ 模板库 Eigen 的 C++ 项目编写 makefile?

python - 如何更好地预处理图像以获得更好的深度学习结果?

tensorflow - 如何将 tflite 模型转换为 Tensorflow 中的卡住图 (.pb)?