Go Down

Topic: multiple definition error (Read 1 time) previous topic - next topic

wally_32

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

patduino

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
There are 10 types of people in the world, those that understand binary, and those that don't.

wally_32

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




patduino

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.
There are 10 types of people in the world, those that understand binary, and those that don't.

wally_32

thanks...

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

:) :)

patduino

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

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

Go Up