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:
- It is closed without specific information, if it’s resolved or not.
- There is a comment, which states, that if similar issue happens in future, it should be opened as new issue
- 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)
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
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
building script
@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>
:I added
-I../tensorflow/third_party/eigen3
which allows it to find theTensor
header, but … that file seems to#include
itself??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 inthird_party/eigen3
just mirror the structure of Eigen and#include
themselves.In 2016 they actually
#include
d a different directory, e.g.But in July 2016 Igor Babuschkin changed them all like this:
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!