C++ 致命错误:特征/密集:没有这样的文件或目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23284473/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 00:23:55  来源:igfitidea点击:

fatal error: Eigen/Dense: No such file or directory

c++debian

提问by quant

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

我安装libeigen3-dev是为了使用 Eigen 3 编译程序。当我包含一个文件时,例如Eigen/Dense当我尝试运行时出现此错误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

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?)

因为我通过 aptitude 安装了 Eigen 包,所以 GCC 不应该自动找到包含目录吗?为什么在安装库时会自动找到 boost 和 OpenGL 而不是 Eigen?(请注意, eigen 是一个仅限头文件的库,但这应该无关紧要吧?)

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

运行g++ src/main.cpp -MMD -std=c++11 --verbose产生以下输出:

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.

采纳答案by laune

Run your compiler with the --verboseswitch:

使用--verbose开关运行编译器:

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.

如果您的包含与此输出中显示的路径之一相关,则您不必使用-I. 这取决于 gcc 的配置方式,也取决于其他东西的安装位置。

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

请注意,.通常不在 -I 路径中。

Later

之后

After exchanging a couple of comments it is clear that /usr/include/eigen3/Eigen/Denseshould 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/eigen3is mandatory.

在交换了一些评论之后,很明显/usr/include/eigen3/Eigen/Dense应该可以包含 by #include <Eigen/Dense>,而不是 by #include <eigen3/Eigen/Dense>。因此,必须添加命令行选项-I /usr/include/eigen3

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.

某些安装是否选择将头文件安装到编译成 gcc 的目录中的某个目录中,取决于默认值、分发者做出的决定或安装期间做出的决定。我会说“经常使用”的头文件(Boost)很好地放在 /usr/local/include 中,而一些“精英”的东西最好放在它自己的目录中。

回答by kbrown

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:

我在 Ubuntu 14 机器上遇到了同样的问题。最终创建了符号链接来解决它。将 eigen3 安装在 /usr/local/include 中,请执行以下操作:

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>

回答by raksi

Change

改变

#include <Eigen/Dense>

to

#include <eigen3/Eigen/Dense>

回答by Yuchen Zhong

Should use the following:

应使用以下内容:

#if defined __GNUC__ || defined __APPLE__
#include <Eigen/Dense>
#else
#include <eigen3/Eigen/Dense>
#endif

回答by scottlittle

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

这对我有用(使用 Macports 在 Mac OS 10.11 上安装 Shogun):

cd ${macports_prefix}/include
sudo ln -sf eigen3/Eigen Eigen
sudo ln -sf eigen3/unsupported unsupported

回答by badPhysicist

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

如果您按照Eigen主站点上的入门说明进行操作,那么您就不会出错。

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.

推测一下,下载然后将 Eigen 源代码解压缩到选择的目录中。接下来将“Eigen”目录复制到/usr/local/include/. 注意这是提取的目录结构中名为“Eigen”的目录,而不是整个目录结构本身。它在 Ubuntu 14.04 虚拟机上对我有用。