fatal error: Eigen/Dense: No such file or directory
Asked Answered
P

11

50

I have installed libeigen3-dev in order to compile programs using Eigen 3. when I include a file, such as Eigen/Dense I get this error when I try to run g++:

user@office-debian:~/Documents/prog$ g++ src/main.cpp -MMD -std=c++11
In file included from src/main.cpp:9:0:
src/tdefs.h:16:23: fatal error: Eigen/Dense: No such file or directory
compilation terminated.

Running the following line works fine:

g++ -I /usr/include/eigen3/ src/main.cpp -MMD -std=c++11

shouldn't that include directory be automatically found by GCC because I installed the Eigen package through aptitude? Why are boost and OpenGL found automatically when I install the libraries but not Eigen? (Note that eigen is a header-only library, but that shouldn't matter right?)

Running g++ src/main.cpp -MMD -std=c++11 --verbose produces the following output:

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.7/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.7.2-5' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --with-arch-32=i586 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.7.2 (Debian 4.7.2-5) 
COLLECT_GCC_OPTIONS='-MMD' '-std=c++11' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/4.7/cc1plus -quiet -v -imultiarch x86_64-linux-gnu -MMD main.d -D_GNU_SOURCE src/main.cpp -quiet -dumpbase main.cpp -mtune=generic -march=x86-64 -auxbase main -std=c++11 -version -o /tmp/ccoYRPKY.s
GNU C++ (Debian 4.7.2-5) version 4.7.2 (x86_64-linux-gnu)
    compiled by GNU C version 4.7.2, GMP version 5.0.5, MPFR version 3.1.0-p10, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.7
 /usr/include/c++/4.7/x86_64-linux-gnu
 /usr/include/c++/4.7/backward
 /usr/lib/gcc/x86_64-linux-gnu/4.7/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
GNU C++ (Debian 4.7.2-5) version 4.7.2 (x86_64-linux-gnu)
    compiled by GNU C version 4.7.2, GMP version 5.0.5, MPFR version 3.1.0-p10, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 66d178dd81da8c975e003e06d9f5e782
In file included from src/main.cpp:9:0:
src/tdefs.h:16:23: fatal error: Eigen/Dense: No such file or directory
compilation terminated.
Paella answered 25/4, 2014 at 4:56 Comment(0)
M
48

Change

#include <Eigen/Dense>

to

#include <eigen3/Eigen/Dense>
Merideth answered 25/4, 2014 at 17:14 Comment(2)
Looking through the directories, this one makes most sense to me. But symlinks work too I guess.Malaysia
I second that! Thanks @MeridethPoree
A
55

I had this same problem on my Ubuntu 14 box. Ended up creating symlinks to get around it. With eigen3 installed in /usr/local/include do the following:

cd /usr/local/include
sudo ln -sf eigen3/Eigen Eigen
sudo ln -sf eigen3/unsupported unsupported

You should now be able to include the headers by:

#include <Eigen/Dense>
#include <unsupported/Eigen/FFT>
Autohypnosis answered 27/8, 2014 at 22:31 Comment(7)
This happens with a surprising number of libraries on Ubuntu and related distros. They put things into a separate folder to avoid possible conflicts. Your solution is the most elegant I've been able to find to-date.Exhibitioner
Thanks Mad Physicist! The above symlink fix seems to be needed even if you install the library by doing "sudo apt-get install libeigen3-dev". The only difference is that eigen3 is in /usr/include instead of /usr/local/includeAutohypnosis
Symlinking is definitely the preferred solution, instead of using clumsy -I specifiers in the compiler. BTW, this procedure is also suggested in the installation webpage of Eigen.Syncope
This really aught to be the selected answer.Tree
Sometimes eigen3 is located under /usr/include/.Cromlech
Still an issue four years later and this solution still works.Citrin
Tried this on Ubuntu 16 six years later and it worked.Provolone
M
48

Change

#include <Eigen/Dense>

to

#include <eigen3/Eigen/Dense>
Merideth answered 25/4, 2014 at 17:14 Comment(2)
Looking through the directories, this one makes most sense to me. But symlinks work too I guess.Malaysia
I second that! Thanks @MeridethPoree
T
12

Run your compiler with the --verbose switch:

g++ --verbose ...

If your includes are relative to one of the paths shown in this output, you don't have to use -I. It depends how gcc has been configured, and it depends where that other stuff is installed.

Note that . is typically not in the -I paths.

Later

After exchanging a couple of comments it is clear that /usr/include/eigen3/Eigen/Dense should be include-able by #include <Eigen/Dense>, but not by #include <eigen3/Eigen/Dense>. Therefore, the addition of the command line option -I /usr/include/eigen3 is mandatory.

Whether some installation selects to install header files into a directory that in one of the ones compiled into gcc, depends on the default, a decision made by the distributor, or a decision made during installation. I'd say that "frequently used" header files (Boost) are well placed into /usr/local/include while some "elitist" stuff would be better off in a directory of its own.

Truscott answered 25/4, 2014 at 5:8 Comment(4)
I did that and placed the result in the OP. It's clearly including /usr/include. Does that not include subdirectories as well? should I add a symlink to /usr/include/eigen3/Eigen and place it in usr/include/?Paella
Is your #include naming all of the relative path from /usr/include? There is also a subtle difference between using <...> and "..." around the (relative) pathname.Truscott
No, it's not. But I want my code to be portable (I'll be compiling it on nix and windows systems), so I just did #include <Eigen/Dense>. I know I could do #include <eigen3/Eigen/Dense> but then my code will break on windows or when/if I upgrade to eigen4.Paella
@ArmanSchwarz I hope my additions to the answer are satisfactory.Truscott
T
9

Should use the following:

#if defined __GNUC__ || defined __APPLE__
#include <Eigen/Dense>
#else
#include <eigen3/Eigen/Dense>
#endif
Toler answered 18/1, 2016 at 19:31 Comment(0)
O
8

This worked for me (using Macports for installing Shogun on Mac OS 10.11):

cd ${macports_prefix}/include
sudo ln -sf eigen3/Eigen Eigen
sudo ln -sf eigen3/unsupported unsupported
Observation answered 20/1, 2016 at 16:1 Comment(0)
D
2

I'm using Ubuntu 22.04, with Eigen installed by

sudo apt install libeigen3-dev

according to the above method (the answer from scottlittle), I link the Eigen to /usr/include by

cd ~/usr/include
sudo ln -sf eigen3/Eigen Eigen
sudo ln -sf eigen3/unsupported unsupported

After this step, I can use

#include <Eigen/Dense>

instead of

#include <eigen3/Eigen/Dense>
Danit answered 1/5, 2022 at 6:21 Comment(1)
Hi, thanks for your anwser! But there is an extra "~" in first cmd of the second code block.Lampert
C
1

If you are working on a Linux server, and you have to install Eigen to a local directory, you can try to solve the problem by following the steps:

  1. Download, install, and extract Eigen source code from the official website.
  2. Copy the Eigen folder to a directory where your local lib is. In my case, I downloaded, unzipped and install eigen-3.4.0, and then I copied the entire folder Eigen in /eigen-3.4.0/Eigen/ to my local include /anywhere/include/Eigen.
  3. Add this path when you run g++ -g yourcode.cpp -I /anywhere/include -L /anywhere/lib'
Cramoisy answered 10/9, 2021 at 16:10 Comment(1)
How to include eigen package into cmakelist and how to use ? i am using windows osHahnke
C
0

You can add this in your CMakeLists.txt

set(EIGEN3_DIR /usr/include/eigen3)

...

include_directories(${EIGEN3_DIR})
Crossman answered 6/3, 2023 at 11:1 Comment(0)
S
0

In my case I was using cmake, I had a broken CMakeLists.txt in my project. I fixed it by adding this line

target_link_libraries(my_project Eigen3::Eigen)
Shellishellie answered 1/6, 2024 at 2:49 Comment(0)
C
0

I had a similar issue and /usr/local/include directory was missing from my computer. But the following steps solved my problem,

  1. find the directory where the Eigen library is installed. I did a brew install and so, for me, it was installed in /opt/homebrew/Celler/eigen/3.4.0_1/include/eigen3/Eigen.
  2. make a directory with sudo mkdir -p /usr/local/include. This might ask for root permissions (Enter the password for your computer).
  3. copy the eigen directory to this folder by sudo cp -r /opt/homebrew/Celler/eigen/3.4.0_1/include/eigen3/Eigen /usr/local/include

This should work at least for macOS environments.

Chelonian answered 5/7, 2024 at 18:4 Comment(0)
S
-3

If you follow the getting started instructions at the main Eigen site then you can't go far wrong.

To surmise, download then extract the Eigen source code into a directory of choice. Next copy the "Eigen" directory into /usr/local/include/. NOTE this is the directory named "Eigen" WITHIN the directory structure extracted, NOT the entire directory structure itself. It worked for me on an Ubuntu 14.04 virtual machine.

Scottyscotus answered 15/1, 2016 at 11:37 Comment(1)
you comment caused me wasting like 1 hour at least. It is the other way around. You must extract the entire eigen-eigen folder in /usr/local/include, under the name of "eigen3". So this must include "Eigen" folder among many othersReduce

© 2022 - 2025 — McMap. All rights reserved.