multiple definition error when using a library

Hi all

I have the following code:


#include <SoftwareSerial.h>
#include <Adafruit_GPS.h>

#include "gps_wrapper.h"

void setup()


void loop()


SoftwareSerial mySerial(3, 2);
Adafruit_GPS GPS(&mySerial);
void setup_gps();
#include "gps_wrapper.h"

void setup_gps()  
     //blah blah blah

The problem is that I get multiple definition errors:

gps_wrapper\gps_wrapper.cpp.o:(.bss.mySerial+0x0): multiple definition of `mySerial'
sketch_apr12a.cpp.o:(.bss.mySerial+0x0): first defined here
gps_wrapper\gps_wrapper.cpp.o:(.bss.GPS+0x0): multiple definition of `GPS'
sketch_apr12a.cpp.o:(.bss.GPS+0x0): first defined here
gps_wrapper\gps_wrapper.cpp.o:(.bss.NMEA1+0x0): multiple definition of `NMEA1'
sketch_apr12a.cpp.o:(.bss.NMEA1+0x0): first defined here
gps_wrapper\gps_wrapper.cpp.o:(.bss.NMEA2+0x0): multiple definition of `NMEA2'
sketch_apr12a.cpp.o:(.bss.NMEA2+0x0): first defined here
gps_wrapper\gps_wrapper.cpp.o:(.bss.c+0x0): multiple definition of `c'
sketch_apr12a.cpp.o:(.bss.c+0x0): first defined here

Any ideas much appreciated.


Variables are to be defined, NOT declared, in a header file.

SoftwareSerial mySerial(3, 2);
Adafruit_GPS GPS(&mySerial);

These are declarations.

Declarations MUST be in the source file.

Ah, shit.

Feel like an idiot now :(