So, I'm trying to record and display an image using CImg but I'm also using a linear algebra library called Eigen. Coincidentally, they each seem to have a macro with the same name, "Success". I've tried doing an #undef but that didn't work out smoothly. So whenever I try to compile, I get this error that "Success" is defined twice in different files. How should I go about removing this error without losing either macro? Help is much appreciated!
4 Answers
The problem arises because CImg includes the X11 header X.h which has a macro called "Success" defined. This macro clashes with the ComputationInfo enum definition in Eigen, since it has an enum value called "Success".
As a workaround, you can undefine "Success" after including CImg, and before including Eigen as so:
#include <CImg/CImg.h>
#ifdef Success
#undef Success
#endif
#include <eigen3/Eigen/Eigen>
See also issue #253 on Eigen's bug tracker: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=253

- 373
- 1
- 8
Neither Eigen nor CImg have such a #define. However, Eigen does have such an enum in the Eigen namespace, so the problem more likely comes from X11 X.h
header file which #define Success.
So, if you need to use Success from X11, then include Eigen's header before X11 ones (or anyone that could include it).
If you need Success from Eigen, then include Eigen last, and #undef Success before it.

- 28,425
- 2
- 65
- 71
You may also want to display the includes of the X11 header files in CImg, by defining macro cimg_display
to 0
before including "CImg.h"
(or put the -Dcimg_display=0
flag when compiling).
Of course, do this only if you don't need the display capabilities of CImg.

- 301
- 1
- 1
If you dont need one of them macros in your code, you can #undef
it between the 2 includes. So, it really depeneds on what you need in your code.

- 378
- 3
- 14
-
Well, I need to use Eigen for linear algebra purposes, and I have one class that includes CImg.h. This particular file has trouble compiling and results in linking errors, saying that a bunch of _X objects are referenced but not in the right way. I know that CImg.h imports X11 files (since I'm on a Mac) so I thought that the linking would work, but I'm confused as to why it doesn't. Any ideas on why I now get linking errors? – user2196118 Mar 14 '14 at 22:32