Steve.Q Steve.Q - 4 months ago 31
Linux Question

Eigen3 from Linux Mint 17.3 repo, SparseMatrix not named

I am trying to use Eigen3 in my project and I get this error when I try to build using CMake and make

/usr/include/eigen3/unsupported/Eigen/src/KroneckerProduct/KroneckerTensorProduct.h:246:11: error: ‘SparseMatrix’ does not name a type
typedef SparseMatrix<Scalar, 0, StorageIndex> ReturnType;


I am using Linux Mint 17.3. I have both the eigen2 and eigen3 libraries and I'm pretty sure the CMake is picking eigen3 (especially given the error message I posted above). I installed eigen3 using the command
sudo apt-get install libeigen3-dev
.
When I run
apt-cache show libeigen3-dev
I get

Package: libeigen3-dev
Priority: extra
Section: universe/libdevel
Installed-Size: 5130
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian Science Maintainers <debian-science-maintainers@lists.alioth.debian.org>
Architecture: all
Source: eigen3
Version: 3.3~beta1-2
Depends: pkg-config
Suggests: libeigen3-doc, libmrpt-dev
Filename: pool/universe/e/eigen3/libeigen3-dev_3.3~beta1-2_all.deb
Size: 662650
MD5sum: bad08ef7b1d166c5bc9903e510a9fb68
SHA1: ef35745fcd047f1a1f18834e02ccef1476d7407c
SHA256: 5c73d97dca2d950ce51bde451deed4b6508b2f6cca9b9b6563218591e029f17b
Description-en: lightweight C++ template library for linear algebra
Eigen 3 is a lightweight C++ template library for vector and matrix math,
a.k.a. linear algebra.
.
Unlike most other linear algebra libraries, Eigen 3 focuses on the simple
mathematical needs of applications: games and other OpenGL apps, spreadsheets
and other office apps, etc. Eigen 3 is dedicated to providing optimal speed
with GCC. A lot of improvements since 2-nd version of Eigen.
Description-md5: 71025bd67be9e83075fd5a0e7ab822a2
Homepage: http://eigen.tuxfamily.org
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Origin: Ubuntu
Supported: 9m


Here's a minimal code snippet:

#include <unsupported/Eigen/KroneckerProduct>
int main() {
return 0;
}


compiling with
g++ -std=c++11 -I /usr/local/include/eigen3 hello.cpp -o hello
:

In file included from /usr/local/include/eigen3/unsupported/Eigen/KroneckerProduct:30:0,
from hello.cpp:4:
/usr/local/include/eigen3/unsupported/Eigen/src/KroneckerProduct/KroneckerTensorProduct.h:246:11: error: ‘SparseMatrix’ does not name a type
typedef SparseMatrix<Scalar, 0, StorageIndex> ReturnType;

Answer

You problem can be solved with correct inlcudes. The first one defines SparseMatrix which corrects your first error message. The second one uses proper path which corrects your second error message.

#include <Eigen/Sparse>
#include <unsupported/Eigen/KroneckerProduct>
int main() {
    return 0;
}