Using Eigen library with Makefile (or Eclipse)

i’ve just found Eigen library1, and i’m exited to try matrix template type!

i’ve installed eigen libs in /usr/local/include/eigen3/
and added in config.make USER_CFLAGS = -I/usr/local/include/eigen3

BUT if i try to run the makefile there are a lot (i think in each declaration of eigen3) was not declared in this scope error.
this is my testApp.cpp:

#include "testApp.h"  
#include <Eigen/Dense>  
using namespace Eigen;  
void testApp::setup(){  
	MatrixXd m(2,2);  
	m(0,0) = 3;  
	m(1,0) = 2.5;  
	m(0,1) = -1;  
	m(1,1) = m(1,0) + m(0,1);  
	cout << "Here is the matrix m:\n" << m << endl;  
void testApp::update(){}  
void testApp::draw(){}  

some advice?

of course if i try to execute this code:

#include <iostream>  
#include <Eigen/Dense>  
using namespace Eigen;  
int main()  
  MatrixXd m(2,2);  
  m(0,0) = 3;  
  m(1,0) = 2.5;  
  m(0,1) = -1;  
  m(1,1) = m(1,0) + m(0,1);  
  std::cout << m << std::endl;  

and compile it as:

g++ -I/usr/local/include/eigen3/ e.cpp

everything is ok

mmh, weird, that should work, can you post the complete config.make?

also you could try installing eigen from apt-get

OF_ROOT = …/…/…
USER_CFLAGS = -I /usr/local/include/eigen3
USER_COMPILER_OPTIMIZATION = -march=native -mtune=native -Os

logging the stderr in a file the first error is:

In file included from /usr/local/include/eigen3/Eigen/Core:250,  
                 from /usr/local/include/eigen3/Eigen/Dense:1,  
                 from src/testApp.cpp:4:  
/usr/local/include/eigen3/Eigen/src/Core/util/Constants.h:375: error: #error The preprocessor symbol 'Success' is defined, possibly by the X11 header file X.h  

and, yeah, inside an openframeworks empty example setuo the code:

cout << Sucess << endl;  

print out a 0

: (
what can be done for resolve this? mayebe a namespace trick?

if someone wants to use Eigen on linux i resolved with a dirty workaround:

#undef Success  
#include <Eigen/Core>  

more info here:

1 Like

thanks for sharing this!

I stumbled into this bug today.

Apparently this is a known problem and I would blame it on X11 who have a non-capital constant defined (Success). Does anybody know of a cleaner workaround? It gets complicated to apply it on bigger projects. I’ve added

 #else // normal linux
        #include <GL/glew.h>
        #include <GL/gl.h>
        #include <GL/glx.h>
        //Eigen has an enum that clashes with X11 Success define, which is ultimately included by pcl
        #ifdef Success
          #undef Success

at ofConstants.h:180

Thanks for sharing, I just tried that in a project locally adding the folder of Eigen, and that solved my problem.

#undef Sucess
#include "../Eigen/Core"
using namespace Eigen

For me it seems to be cleaner to:

#include “…Eigen/whatever…”
#undef Success
#other includes

So first I would include Eigen and then everything else. Eigen3 is a header-only library so it seems cleaner this way because X11 is not header-only and you might mess it up more the other way around I feel…

But to be honest both methods are bad - especially since I am not even using eigen3 by myself, just using soemthing that uses eigen3…