Problems when using MathGL with Eigen

168 views
Skip to first unread message

Julien Gacon

unread,
Nov 12, 2015, 2:16:16 AM11/12/15
to MathGL
Hello everyone,

I lately started to use MathGL for my studies. Eigen (http://eigen.tuxfamily.org/) is another very important library to me and when using both Eigen and MathGL I encounter some very weird problems:
When beginning to program with:

# include <Eigen/Dense>
# include <mgl2/mgl.h>

I suddenly get warnings that the types from Eigen would be "incomplete" (that warning is not there without the # include <mgl2/mgl.h>).
But everything compiles and works fine.

However, when including the libraries the other way round:

# include <mgl2/mgl.h>
# include <Eigen/Dense>

I can't even compile and get huge errors.

It begins with (the whole log is attached as log file)

In file included from /usr/include/c++/5.1.1/complex.h:36:0,
                 from /usr/local/include/mgl2/define.h:268,
                 from /usr/local/include/mgl2/abstract.h:23,
                 from /usr/local/include/mgl2/data_cf.h:23,
                 from /usr/local/include/mgl2/data.h:23,
                 from /usr/local/include/mgl2/mgl_cf.h:24,
                 from /usr/local/include/mgl2/mgl.h:23,
                 from mgl-eigen.cpp:1:
/usr/local/include/Eigen/src/Core/SolveTriangular.h:119:5: error: expected identifier before ‘(’ token
     I = IsLower ? Index : Size - Index - 1,
     ^

and end with:
                        ^
/usr/local/include/Eigen/src/Core/SolveTriangular.h:231:24: error: expected ‘{’ before ‘<’ token
/usr/local/include/Eigen/src/Core/SolveTriangular.h:231:24: error: expected unqualified-id before ‘<’ token
/usr/local/include/Eigen/src/Core/SolveTriangular.h:258:1: error: expected declaration before ‘}’ token
 } // end namespace Eigen

Does anyone know what's going on here?

Kind regards,
Julien

Hutträger

unread,
Nov 14, 2015, 6:34:44 AM11/14/15
to MathGL
Dear Julien,

this is just a guess: do you use "using namespace Eigen;"? Then try to omit this line and rewrite your code with the explicit namespaces before each function call. Probably this helps. I haven't tried it yet, but I think, I will try this library this evening/tomorrow.

Best regards,
Erik

Julien Gacon

unread,
Nov 14, 2015, 7:17:33 AM11/14/15
to MathGL
Dear Erik,

I got the same error when trying to compile the following program:

# include <mgl2/mgl.h>
# include <Eigen/Dense>

int main()
{
   return 0;
}

I thought that maybe there could be a Macro in mgl.h which is not undefined in the end.
Thank you very much, I'm really grateful for any help/ideas!


Best,
Julien
 

Hutträger

unread,
Nov 14, 2015, 8:13:34 AM11/14/15
to MathGL
Dear Julien,

that's strange. I thought, because it depends on the order of inclution, that it is related to some interfering definitions in the headers. Could you please attach the cited logfile, so I can take a look on it? Probably you forgot it in your first message.

Best regards,
Erik

Alexey Balakin

unread,
Nov 14, 2015, 3:16:19 PM11/14/15
to mat...@googlegroups.com
Dear Julien,

"I" is predefined variable for C99 -- see complex.h
http://pubs.opengroup.org/onlinepubs/009695399/basedefs/complex.h.html

MathGL provide interface for C99 complex numbers. So, it need to include the <complex.h>.

You can disable support of C99 complex numbers by setting MGL_HAVE_C99_COMPLEX to 0 (in mgl2/config.h or in CMakeCache.txt).

However, the correct way is not use "I" variable.

12.11.2015 02:16, Julien Gacon пишет:
--
You received this message because you are subscribed to the Google Groups "MathGL" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathgl+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hutträger

unread,
Nov 14, 2015, 3:56:36 PM11/14/15
to MathGL
Dear Julien and Alexey,

I can confirm that with disabled C99 complex support there are no errors or warnings when compiling using g++ with #include <Eigen/Dense> and #include <mgl2/mgl.h>. However as C99 doesn't belong to the C++ standard and Eigen is a pure C++ library using C++ <complex>, I don't think that forcing them to not use "I" is the best response. But I'm quite sure that they will fix this problem. I've noticed them recently.

Best regards,
Erik

Alexey Balakin

unread,
Nov 14, 2015, 3:59:48 PM11/14/15
to mat...@googlegroups.com
Somewhere, there is another advise -- use

#undef I

just after <complex.h>.

14.11.2015 15:56, Hutträger пишет:

Julien Gacon

unread,
Nov 18, 2015, 5:28:57 AM11/18/15
to MathGL
Dear Eric and Alexey,

Thank both of you very much, with "#undef I" it finally works!
The only thing which still bothers me are incomplete type warnings (for the Eigen types) when including MathGL. (The warnings aren't appearing without MathGL).
My code still compiles and runs perfectly fine, has anyone of you an idea what could cause this error?
Might it also be the "I"-variable?

Kind regards,
Julien

Hutträger

unread,
Nov 19, 2015, 2:22:42 AM11/19/15
to MathGL
Dear Julien,

see this paragraph in Eigen's FAQ: http://eigen.tuxfamily.org/index.php?title=FAQ#I_need_help_with_compiler_errors.21

Because I don't see these messages while compiling with Eigen an MathGL (I've deactivated MathGL's C99 complex support), I think it's again related to the C99 complex types and the (no offense) stupid C-preprocessor-define-nonsense commonly used by most C programmers and therefore in included in complex.h.

Best Regards,
Erik

Julien Gacon

unread,
Nov 19, 2015, 6:04:29 AM11/19/15
to MathGL
Dear Erik,

Thank you for your help and patience, now everything's working as it should - no errors, no warnings and nice plots!

Best,
Julien

Hutträger

unread,
Nov 19, 2015, 8:17:04 AM11/19/15
to MathGL
Dear Julien,

no probs. I've searched for a nice matrix library as well and therefore I profitated as well from these investigations.

Best regards,
Erik

Hutträger

unread,
Dec 10, 2015, 7:22:09 AM12/10/15
to MathGL
Dear Julien, dear Alexey,

today I've recieved a bug update stating that Eigen dropped the "I" in their library. In the future Eigen will (hopefully) not interfere with C99 any more.

Best regards,
Erik
Reply all
Reply to author
Forward
0 new messages