VitrualWire Issues

When I compile the example code for the VirtualWire library, I get the following errors.

c:/users/Username/arduino-0017/arduino-0017/hardware/tools/avr/lib/gcc/../../avr/include/math.h:439: error: expected unqualified-id before 'double'

c:/users/Username/arduino-0017/arduino-0017/hardware/tools/avr/lib/gcc/../../avr/include/math.h:439: error: expected `)' before 'double'

c:/users/Username/arduino-0017/arduino-0017/hardware/tools/avr/lib/gcc/../../avr/include/math.h:439: error: expected `)' before 'double'

I'm wondering if it is a version issue. Has anyone had VirtualWire working with arduino 1.7 (0017)?

Interesting, you should delete the VirtualWire file and unzip it again. I have it working for 0017 just fine.
Did you recently change any files other than the VirutalWire?

Also, somebody suggested this when they had problems.. but it should be included in the example:
include these at the top of your sketch

#include <VirtualWire.h>
#undef int
#undef abs
#undef double
#undef float
#undef round

I had the same problem but if I insert the following line following the #include <VirtualWire.h>,
it compiles and runs OK:

#undef round

Not sure why it works or how I came across the work-around. Maybe some proficient C programmer can explain...

You were right, adding the lines worked. It is strange that the example didn't have the code. Looks like I will need to stop assuming that example code works.

The problem is caused by some Arduino definitions (called macros) in the file Wiring.h

A cleaner way to fix it is to make these two changes in the VirtualWire directory :

Move:
#include "WProgram.h"
from VirtualWire.cpp to VirtualWire.h

move:
#include <wiring.h>
from VirtualWire.h to VirtualWire.cpp

mem,
I tried your suggestion and more errors than before:

from C:\Arduino\arduino-0017\hardware\libraries\VirtualWire\VirtualWire.cpp:17:
c:/arduino/arduino-0017/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected unqualified-id before 'int'

c:/arduino/arduino-0017/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected `)' before 'int'

c:/arduino/arduino-0017/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected `)' before 'int'

from C:\Arduino\arduino-0017\hardware\libraries\VirtualWire/VirtualWire.h:16,
from C:\Arduino\arduino-0017\hardware\libraries\VirtualWire\VirtualWire.cpp:17:

c:/arduino/arduino-0017/hardware/tools/avr/lib/gcc/../../avr/include/math.h:439: error: expected unqualified-id before 'double'

c:/arduino/arduino-0017/hardware/tools/avr/lib/gcc/../../avr/include/math.h:439: error: expected `)' before 'double'

c:/arduino/arduino-0017/hardware/tools/avr/lib/gcc/../../avr/include/math.h:439: error: expected `)' before 'double'

Strange, all the examples compile ok for me. Here are the first few lines of the cpp and .h files that I used

VirtualWire.cpp:
// $Id: VirtualWire.cpp,v 1.4 2009/03/31 20:49:41 mikem Exp mikem $
#include "VirtualWire.h"
#include <util/crc16.h>
#include <wiring.h> // this was moved from the .h file to the cpp file

VirtualWire.h:
// $Id: VirtualWire.h,v 1.3 2009/03/30 00:07:24 mikem Exp $
#ifndef VirtualWire_h
#define VirtualWire_h
#include "WProgram.h" // this was moved from the cpp file to the .h file
#include <stdlib.h>

I had the #include <wiring.h> before the #include "VirtualWire.h"

The order is obviously significant.

Was the macro error caused by the "round" function already being defined?

Yes, round is a function in the math library and Arduino also defines it in wiring.h.

I have uploaded a new version 1.4 of VirtualWire which should fix compile problems for all platforms. Pls let me know if any further problems are observed.

Cheers.

Great! We appreciate your efforts.

Thanks mikem...