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

时间:2016-08-29 17:29:26

标签: 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

(这会持续一段时间)

1 个答案:

答案 0 :(得分:0)

我认为你不应该添加所有这些 - 我包括

您可以查看bazel构建系统中的参考C ++示例。

cc_binary。 https://github.com/tensorflow/tensorflow/blob/master/tensorflow/cc/BUILD#L264

标志: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tensorflow.bzl#L111

您可以使用function getPrimes(num) { var a = [...Array(num+1).keys()]; // =[0,1,...,num] a[1] = 0; // 1 is not prime var rt = Math.sqrt(num); // calculate only once for (i=2;i<=rt;i++){ for (var j=i*i; j<=num; j+=i) a[j]=0; } return a.filter(Number); // kick out the zeroes } // run it for 30 var a = getPrimes(30); // Output console.log(a);选项运行bazel build,以查看为构建目标而发出的实际命令。