Can't Instantiate NewSoftSerial From a Class

Hey Arduinians,

Can you help me? I'm doing something I think is simple, but it doesn't work and I don't understand why. Here's the problem.

I have created the beginnings of a GPS class (to do the obvious) and I want it to instantiate it's own serial connection to the GPS hardware. So the GPS class should instantiate an object of the NewSoftSerial class so it can receive data. Easy. But it fails with the error:

LifeClock99.cpp.o:(.bss.gps+0x0): multiple definition of `gps'
GPS.cpp.o:/GPS.h:17: first defined here

If I instaintate the NewSoftSerial object in the main sketch (commented out below) it compiles just fine. Why is that? Here's all my code.

Main.pde:

#include "GPS.h"

//NewSoftSerial gps(GPS_READ_PIN, GPS_WRITE_PIN);

void setup()
{
  Serial.begin(115200);
  Serial.println("setup()");
}

void loop()
{
}

GPS.h:

#ifndef GPS_h
#define GPS_h

#include "NewSoftSerial.h"

// Pinouts: http://shieldlist.org/sparkfun/gps
#define GPS_WRITE_PIN    2
#define GPS_READ_PIN     3
#define GPS_BAUD      4800

NewSoftSerial gps(GPS_READ_PIN, GPS_WRITE_PIN);

class GPS
{
  public:
  private:
};

#endif

GPS.cpp

#include "GPS.h"

The cpp code includes GPS.h, which causes a NewSoftSerial object to be created.

The sketch include GPS.h, which causes a NewSoftSerial object, of the same name, to be created.

Which one is to be used by the sketch? Which one is to be used by the class? Which one is to be used by an instance of the class?

Now, if the gps object were a member of the class, as it should be, the "problem" would go away.

Thanks PaulS. Doesn't the macro guard prevent the multiple instantiation?

It guards against multiple inclusion within one object module. With a sketch and a library, you have two object modules, hence two instances of the class with the same name.