tensorflow: While compiling external app -> fatal error: unsupported/Eigen/CXX11/Tensor: No such file or directory

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): It’s a C++ code from this tutorial
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 16.04
  • TensorFlow installed from (source or binary): Source
  • TensorFlow version (use command below): Release 1.4.0
  • Python version: 3.5
  • Bazel version (if compiling from source): 0.6.1
  • CUDA/cuDNN version: no CUDA
  • GPU model and memory: no GPU
  • Exact command to reproduce: g++ -I /opt/tensorflow -I /opt/tensorflow/bazel-genfiles loader.cpp

Describe the problem

I have a problem while trying to use tensorflow in external app. I took the code from the tutorial above, built tensorflow with following command: bazel build //tensorflow:libtensorflow_cc.so. Now, I want to build my external application with tensorflow. While compiling with given command, I receive an error. I also tried compiling with cmake and proper include_directories directive, but to no avail.

Source code / logs

The problematic line of code is: #include "tensorflow/core/public/session.h"
Compiling with command: g++ -I /opt/tensorflow -I /opt/tensorflow/bazel-genfiles loader.cpp generates error:

In file included from /opt/tensorflow/tensorflow/core/framework/tensor.h:19:0,
                 from /opt/tensorflow/tensorflow/core/public/session.h:24,
                 from loader.cpp:1:
/opt/tensorflow/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1:42: fatal error: unsupported/Eigen/CXX11/Tensor: No such file or directory
compilation terminated.

Whole code snippet can be seen in the tutorial link above

Remarks

A similar issue is #4680 but:

  1. It is closed without specific information, if it’s resolved or not.
  2. There is a comment, which states, that if similar issue happens in future, it should be opened as new issue
  3. The use case there was not precisely using external app on Ubuntu, but on RaspberryPi instead. Thus, I’m submitting new issue for this case.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 7
  • Comments: 26 (16 by maintainers)

Most upvoted comments

Closing due to lack of activity.

Has anyone been able to resolve the issues ?

I have included “tensorflow/third_party/eigen3” but I get below error

tensorflow/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1:42: error: #include nested too deeply #include “unsupported/Eigen/CXX11/Tensor”

  • You don’t have to use Bazel to build tensorflow
  • Your code don’t have to place in the Tensorflow repo.

1. Bazel build — success

follow the instruction of https://www.tensorflow.org/api_guides/cc/guide

2. g++ build — success

The following error comes from the wrong eigen header, as mentioned by @leftofcenter

eigen3/Eigen/Core:1:22: error: #include nested too deeply

building script

g++ -std=c++11 example.cc -o example  \
  -I /root/tensorflow-1.10/bazel-genfiles \
  -I /root/tensorflow-1.10  \
  -I /usr/local/lib/python2.7/dist-packages/tensorflow/include/external/eigen_archive  \
  -I /usr/local/lib/python2.7/dist-packages/tensorflow/include \
  -L /root/tensorflow-1.10/bazel-bin/tensorflow \
  -l tensorflow_cc \
  -l tensorflow_framework

Has anyone been able to resolve the issues ?

I have included “tensorflow/third_party/eigen3” but I get below error

tensorflow/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1:42: error: #include nested too deeply #include “unsupported/Eigen/CXX11/Tensor”

@ashokbugude did you able to solve it? I have a similar problem

When I compile it with GCC I have no problem But when I try to use the same code with ROS package and compiling with catkin_make I get the same error

EDIT: Found the solution in compiler instructions I included the following folders: /usr/local/include/tensorflow/ /usr/local/include/tensorflow/tensorflow/contrib/makefile/downloads/eigen/ /usr/local/include/tensorflow/bazel-tensorflow/tensorflow/contrib/makefile/gen/protobuf/include/ /usr/local/include/tensorflow/bazel-tensorflow/tensorflow/contrib/makefile/downloads/nsync/public/

Regarding OP’s command that failed which was, g++ -I /opt/tensorflow -I /opt/tensorflow/bazel-genfiles loader.cpp I placed the source code in the tensorflow tree that I built from source so paths are different:

g++ -c -std=c++11 \ -I …/…/… -I …/…/…/bazel-genfiles \ -I/usr/local/lib/python2.7/dist-packages/tensorflow/include/external/eigen_archive/ \ loader.cpp

it compiles.

“unsupported/Eigen/CXX11/Tensor” is in the directory of the 3rd -I. The Tensor header is not including itself that has been wrongly assumed by some posters. This assumes you have installed the python .whl file that the build generates.

So I didn’t realise that you can’t actually link with Tensorflow as a normal C++ library from an external tool. You have to use Bazel and your code has to be inside the Tensorflow repo. It does tell you this in the C++ tutorial but it is very unexpected and I hadn’t read that.

Anyway, using Bazel resolved the errors about Eigen. It seems like it downloads it automatically somehow.

Haven’t had a chance to look into the Eigen headers. The documentation being out of date I will fix; it needs to use tf_cc_binary to link in its dependencies (https://github.com/tensorflow/tensorflow/issues/13855).

I have the same issue but it happens when I #include <tensorflow/core/framework/op_kernel.h>:

In file included from ../tensorflow/tensorflow/core/framework/op_kernel.h:23:
In file included from ../tensorflow/tensorflow/core/framework/allocator.h:23:
In file included from ../tensorflow/tensorflow/core/framework/numeric_types.h:21:
../tensorflow/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1:10: fatal error: 'unsupported/Eigen/CXX11/Tensor' file not found
#include "unsupported/Eigen/CXX11/Tensor"

I added -I../tensorflow/third_party/eigen3 which allows it to find the Tensor header, but … that file seems to #include itself??

$ cd ../tensorflow/third_party/eigen3
$ ls unsupported/Eigen/CXX11/Tensor

#include "unsupported/Eigen/CXX11/Tensor"

#ifdef _WIN32
#ifndef SLEEP_FUNC_HEADER_GUARD
#define SLEEP_FUNC_HEADER_GUARD
inline void sleep(unsigned int seconds) { Sleep(1000*seconds); }
#endif

// On Windows, Eigen will include Windows.h, which defines various
// macros that conflict with TensorFlow symbols. Undefine them here to
// prevent clashes.
#undef DeleteFile
#undef ERROR
#undef LoadLibrary
#endif  // _WIN32

I don’t see how this could ever work. Also that file doesn’t match the current Tensor header. In fact it seems like all of the files in third_party/eigen3 just mirror the structure of Eigen and #include themselves.

In 2016 they actually #included a different directory, e.g.

$ cd ../tensorflow/third_party/eigen3/
$ ls Eigen/Core

#include "eigen-eigen-b4fa9622b809/Eigen/Core"

But in July 2016 Igor Babuschkin changed them all like this:

#include "Eigen/Core"

Can’t see how that is supposed to work given that there is no other copy of Eigen in the source. Am I supposed to have a copy of it on my system? Anyway I guess @ibab would know!