LedControl library fails in Arduino IDE 0012

Hi. I've been loving the LEDcontrol library (http://www.arduino.cc/playground/Main/LedControl), but recently upgraded from 0010 to Arduino 0012 IDE, and now unfortunately even compiling the following fails (not just warnings):

#include "LedControl.h"
void setup() {}
void loop() {}

The errors are:

In file included from C:\Users\User\Desktop\ecw\Arduino Coding\arduino-0012\hardware\cores\arduino/WProgram.h:4,


c:/users/user/desktop/ecw/arduino coding/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:80: error: expected unqualified-id before 'int'


c:/users/user/desktop/ecw/arduino coding/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:80: error: expected `)' before 'int'


c:/users/user/desktop/ecw/arduino coding/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:80: error: expected `)' before 'int'


c:/users/user/desktop/ecw/arduino coding/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected unqualified-id before 'int'


c:/users/user/desktop/ecw/arduino coding/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected `)' before 'int'


c:/users/user/desktop/ecw/arduino coding/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected `)' before 'int'


c:/users/user/desktop/ecw/arduino coding/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:144: error: expected identifier before '(' token


c:/users/user/desktop/ecw/arduino coding/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:144: error: expected `)' before '(' token


c:/users/user/desktop/ecw/arduino coding/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:144: error: expected ',' or '...' before '(' token


c:/users/user/desktop/ecw/arduino coding/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:144: error: expected initializer before ')' token


c:/users/user/desktop/ecw/arduino coding/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:176: error: '__compar_fn_t' has not been declared


In file included from C:\Users\User\Desktop\ecw\Arduino Coding\arduino-0012\hardware\cores\arduino/WProgram.h:6,

It worked (with warnings) in 0011 and worked fine in 0010.
I've replicated the errors above in XP Pro and Vista.

Has anyone else tried this?

Ok, a workaround for this problem is to open the file hardware/cores/arduino/wiring.h and change

#define int(x)     ((int)(x))
#define char(x)    ((char)(x))
...
#define degrees(rad) ((rad)*RAD_TO_DEG)
#define sq(x) ((x)*(x))

to

[glow]#if 0 // remove this block![/glow]
#define int(x)     ((int)(x))
#define char(x)    ((char)(x))
...
#define degrees(rad) ((rad)*RAD_TO_DEG)
#define sq(x) ((x)*(x))
[glow]#endif[/glow]

These definitions, in particular int, double, float, round and abs, seem to collide with the standard C/C++ headers.

Mikal

If you find modifying system headers distasteful, I think adding the following lines AFTER the #include "LedControl.h" should also resolve the problem:

#include "LedControl.h"
#undef int
#undef abs
#undef double
#undef float
#undef round

Mikal

Hi,
here is a workaround where you only have to make some changes to the LedControl-library sources themselfes:

To make the LedControl library compile under arduino-0012 you have to do the following:

  1. Download and unzip the library code to arduino-0012/hardware/libraries (Standard procedure, you probably did that already)
  2. Open the file LedControl.h with your favorite Editor and change the line
    #include <WConstants.h>
    to
    #include <WProgram.h>
  3. Open the file LedControl.cpp with your favorite Editor and delete the line
    #include "WProgram.h"

Now the library should compile (with a warning about a missing newline which can be safely ignored)

I will come up with a real bugfix after my holidays which start right now.

Eberhard

I have just uploaded a bugfix release of the library to the playground, that compiles under arduino-0010 up to arduino-0012.

http://www.arduino.cc/playground/Main/LedControl

(pre 0010 versions should also work, but I'd rather suggest to update your arduino-version if you still run this old stuff)

Eberhard