“unsupported/Eigen/CXX11/Tensor: No such file or d

2020-06-20 07:53发布

问题:

I'm trying to use tensorflow as a external library in my C++ application (mainly following this tutorial). What I done so far:

  1. I have cloned the tensorflow reporitory (let's say, that the repo root dir is $TENSORFLOW)
  2. Run /.configure (which all settings default, so no CUDA, no OpenCL etc.).
  3. Build shared library with bazel build -c /opt //tensorflow:libtensorflow_cc.so (build completed successfully)
  4. Now I'm trying to #include "tensorflow/core/public/session.h". But after including it (and adding $TENSORFLOW and $TENSORFLOW/bazel-genfiles to include path), I'm receiving error:

    $TENSORFLOW/tensorflow/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1:42:
    fatal error: unsupported/Eigen/CXX11/Tensor: No such file or directory
    

There is a github issue created for similar problem, but it's marked as closed without any solution provided. Also I tried with master branch as well as v.1.4.0 release.

Do you happen to know, what could cause this kind of problem and how to deal with it?

回答1:

I (and many others) agonized over the same problem. It probably can be solved using bazel but I don't know that tool well enough and now I solve this using make. The source of confusion is that a file named Tensor is included and it itself includes a file named Tensor, which has caused some people to wrongly conclude Tensor is including itself.

If you built and installed the python .whl file there will be a tensorflow directory in dist-packages and an include directory below that, e.g. on my system:

/usr/local/lib/python2.7/dist-packages/tensorflow/include

From the include directory

find . -type f -name 'Tensor' -print
./third_party/eigen3/unsupported/Eigen/CXX11/Tensor
./external/eigen_archive/unsupported/Eigen/CXX11/Tensor

The first one has

#include "unsupported/Eigen/CXX11/Tensor"

and the file that should satisfy this is the second one.

So to compile session.cc that includes session.h, the following will work

INC_TENS1=/usr/local/lib/python2.7/dist-packages/tensorflow/include/
INC_TENS2=${INC_TENS1}external/eigen_archive/
gcc -c -std=c++11 -I $INC_TENS1 -I $INC_TENS2 session.cc

I've seen claims that you must build apps from the tensorflow tree and you must use bazel. However, I believe all the header files you need are in dist-packages/tensorflow/include and at least for starters you can construct makefile or cmake projects.



回答2:

the problem was actually in the relative path of the header file taken in the Tensor file.

installed path for Tensor is /usr/include/eigen3/unsupported/Eigen/CXX11/Tensor

but mentioned in the Tensor file is "unsupported/Eigen/CXX11/Tensor"

So there should be an entry upto /usr/include/eigen3/ in the project path to run this correctly so that it can be used.