Using Eigen library with Makefile (or Eclipse)


#1

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

EDIT:
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


#2

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

also you could try installing eigen from apt-get


#3

OF_ROOT = …/…/…
USER_CFLAGS = -I /usr/local/include/eigen3
USER_LDFLAGS =
USER_LIBS =
USER_COMPILER_OPTIMIZATION = -march=native -mtune=native -Os
EXCLUDE_FROM_SOURCE=“bin,.xcodeproj,obj,.git”


#4

mhmmm
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  
  

EDIT:
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?


#5

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

  
#undef Success  
#include <Eigen/Core>  

more info here:
http://eigen.tuxfamily.org/bz/show-bug.cgi?id=253


#6

thanks for sharing this!


#7

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
        #endif
#endif

at ofConstants.h:180


#8

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