Multiple definition errors on compile

I have written code in a single file which works on an Arduino with display but when splitting it into .h and .cpp files I get multiple definition errors. I guess because I use functions within other functions in the same class. How do I get around this please?

Display.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <Display.h>

//		   "                "	
char testText1[] = "   Greg Cross   ";


void setup() {
	Display display(8,9,3);
	display.CLEAR();
	display.DisplayString(0,0,testText1,16);
}

void loop() {
  }



Display.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef Display_h
#define Display_h

#include "Arduino.h"

class Display
{
	public:
		Display(int CS, int SID, int CLK);
		void WriteByte(int d);
		void WriteCommand(int cmd);
		void Initialise();
		void WriteData(int cmd);
		void CLEAR(void);
		void DisplayString(int X,int Y,char ptr[],int d);
	private:
		int _CS;
		int _SID;
		int _CLK;
		};
		
#endif 

Display.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <Display.h>


#include "Arduino.h"


Display::Display(int CS, int SID, int CLK)
{
	pinMode(CS, OUTPUT);
	pinMode(SID, OUTPUT);
	pinMode(CLK, OUTPUT);
	_CS = CS;
	_SID = SID;
	_CLK = CLK;
	}
	
void Display::WriteByte(int d)
{
    digitalWrite(_CS, HIGH);
    delay(5);
    shiftOut(_SID, _CLK, MSBFIRST, d);
    digitalWrite(_CS, LOW);
	}
	
void Display::WriteCommand(int cmd)
{
	int _H_data,_L_data;
	_H_data = cmd;
	_H_data &= 0xf0;           
	_L_data = cmd;             
	_L_data &= 0x0f;           
	_L_data <<= 4;            
	WriteByte(0xf8);         
	WriteByte(_H_data);
	WriteByte(_L_data);
   }
   
void Display::Initialise()
{
	digitalWrite(_CS, LOW);
	delay(80);
	WriteCommand(0x30);        
	WriteCommand(0x0c);        
	WriteCommand(0x01);       
	WriteCommand(0x06);
  }
  
void Display::WriteData(int cmd)
{
	int _H_data,_L_data;
	_H_data = cmd;
	_H_data &= 0xf0;           
	_L_data = cmd;            
	_L_data &= 0x0f;           
	_L_data <<= 4;             
	WriteByte(0xfa);          
	WriteByte(_H_data);
	WriteByte(_L_data);
  }
  
void Display::CLEAR()
{
    WriteCommand(0x30);
    WriteCommand(0x01);
	}
	
void Display::DisplayString(int X,int Y,char ptr[],int d)
{
	int i;
	  switch(X)
	   {
		 case 0:  Y|=0x80;break;

		 case 1:  Y|=0x90;break;

		 case 2:  Y|=0x88;break;

		 case 3:  Y|=0x98;break;

		 default: break;
	   }

  WriteCommand(Y); 

  for(i=0;i<d;i++)
    { 
      WriteData(ptr[i]);
    }
   }

Error list:
Display\Display.cpp.o: In function `Display::WriteByte(int)':
C:\Program Files (x86)\Arduino\libraries\Display/Display.cpp:17: multiple definition of `Display::WriteByte(int)'
Display.cpp.o:C:\Users\Greg\AppData\Local\Temp\build6302322873889136374.tmp/Display.cpp:17: first defined here
c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions
Display\Display.cpp.o: In function `Display::WriteData(int)':
C:\Program Files (x86)\Arduino\libraries\Display/Display.cpp:48: multiple definition of `Display::WriteData(int)'
Display.cpp.o:C:\Users\Greg\AppData\Local\Temp\build6302322873889136374.tmp/Display.cpp:48: first defined here
Display\Display.cpp.o: In function `Display::WriteCommand(int)':
C:\Program Files (x86)\Arduino\libraries\Display/Display.cpp:25: multiple definition of `Display::WriteCommand(int)'
Display.cpp.o:C:\Users\Greg\AppData\Local\Temp\build6302322873889136374.tmp/Display.cpp:25: first defined here
Display\Display.cpp.o: In function `Display::DisplayString(int, int, char*, int)':
C:\Program Files (x86)\Arduino\libraries\Display/Display.cpp:67: multiple definition of `Display::DisplayString(int, int, char*, int)'
Display.cpp.o:C:\Users\Greg\AppData\Local\Temp\build6302322873889136374.tmp/Display.cpp:67: first defined here
Display\Display.cpp.o: In function `Display::CLEAR()':
C:\Program Files (x86)\Arduino\libraries\Display/Display.cpp:61: multiple definition of `Display::CLEAR()'
Display.cpp.o:C:\Users\Greg\AppData\Local\Temp\build6302322873889136374.tmp/Display.cpp:61: first defined here
Display\Display.cpp.o: In function `Display::Initialise()':
C:\Program Files (x86)\Arduino\libraries\Display/Display.cpp:38: multiple definition of `Display::Initialise()'
Display.cpp.o:C:\Users\Greg\AppData\Local\Temp\build6302322873889136374.tmp/Display.cpp:38: first defined here
Display\Display.cpp.o: In function `Display':
C:\Program Files (x86)\Arduino\libraries\Display/Display.cpp:7: multiple definition of `Display::Display(int, int, int)'
Display.cpp.o:C:\Users\Greg\AppData\Local\Temp\build6302322873889136374.tmp/Display.cpp:7: first defined here
Display\Display.cpp.o: In function `Display':
C:\Program Files (x86)\Arduino\libraries\Display/Display.cpp:7: multiple definition of `Display::Display(int, int, int)'
Display.cpp.o:C:\Users\Greg\AppData\Local\Temp\build6302322873889136374.tmp/Display.cpp:7: first defined here
core.a(main.cpp.o): In function `main':
C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/main.cpp:11: undefined reference to `setup'
C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/main.cpp:14: undefined reference to `loop'
You don't need to include Arduino.h in cpp file too
Topic archived. No new replies allowed.