Pages: [1]   Go Down
Author Topic: multiple definition error  (Read 1716 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i want to define a LiquidCrystal variable out of main unit....
but when compiling the whole program, "multiple definition" error occurs...   smiley-mad
Logged

Indiana, US
Offline Offline
Full Member
***
Karma: 12
Posts: 204
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Wally,

You really didn't provide enough detail for us to understand what you did or what you're trying to do...

Most likely you are creating a variable or type that already exists, or you are including a header file that has a definition that already exists in another one.

Pat
Logged

There are 10 types of people in the world, those that understand binary, and those that don't.

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i want to create a library which contains routines that use LCD functions.
my library's begining:


//lcd_lib.cpp
#include <LiquidCrystal.h>
LiquidCrystal sysMon(12, 11, 5, 4, 3, 2);
.
.
.


And main unit:


//main_unit.cpp
#include "Arduino.h"
#include <LiquidCrystal.h>
#include "lcd_lib.cpp"

void setup()
{
...
 sysMon.begin(8,2,0);
...
}

.
.
.
.


if i compile this project in eclipse IDE, this message occurs:

../lcd_lib.cpp:13: multiple definition of `sysMon'
./main_unit.o:(.bss.sysMon+0x0): first defined here



Logged

Indiana, US
Offline Offline
Full Member
***
Karma: 12
Posts: 204
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ahhh.  I see what you're doing... try it again without the following line:

#include "lcd_lib.cpp"

You don't include CPP files into CPP files, or you will get duplicate code.  The #include pre-processor operation essentially copies and pastes the included file into your CPP file before it compiles it.  The compiler saw your sysMon definition twice.
Logged

There are 10 types of people in the world, those that understand binary, and those that don't.

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks...

i used #include direktive with header file (lcd_lib.h) and problem solved...

smiley smiley
Logged

Indiana, US
Offline Offline
Full Member
***
Karma: 12
Posts: 204
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Great!  Good luck with your project. LCDs can be a lot of fun.

Pat.
Logged

There are 10 types of people in the world, those that understand binary, and those that don't.

Pages: [1]   Go Up
Jump to: