Error with global LiquidCrystal object

First, hello everybody! This is my first post in the forum (though I have been reading silently up here).
Second, excuse me for my english I'm working in it.

Third:
I'm having trouble and I can't solve it despite I read a lot of pages and pages.

Briefly: I'm working in a project using LiquidCrystal lib among other things.
The project grew enough, so I began to separate it in multiple source files each with their respective header file.

I use some global variables which are declared in a header file using extern keyword and then defined once in a source file. That worked fine with integers and that kind of datatype.

The problem started when i attemped to do the same with a LiquidCrystal object, for example:

header.h

#ifndef _PANTALLAS_h
#define _PANTALLAS_h

#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

#include "LiquidCrystal.h"
#define (.....................) //several defines

extern LiquidCrystal lcd (OPER_DISPL_RS, OPER_DISPL_E, OPER_DISPL_DB4, OPER_DISPL_DB5, OPER_DISPL_DB6, OPER_DISPL_DB7); //Syntax lcd (rs, enable, d4, d5, d6, d7)

#endif

source.c

#include "header.h"

LiquidCrystal lcd (OPER_DISPL_RS, OPER_DISPL_E, OPER_DISPL_DB4, OPER_DISPL_DB5, OPER_DISPL_DB6, OPER_DISPL_DB7);
//Syntax lcd (rs, enable, d4, d5, d6, d7)

I got this error at the output:

Pantallas.cpp:9:19: error: redefinition of 'LiquidCrystal lcd'
Pantallas.h:26:22: error: 'LiquidCrystal lcd' previously declared here

The central question is: What is the way to get a global LiquidCrystal Object across multiple source files??

Thanks a lot!!!!!!!!

Why is your library declaring an instance of LiquidCrystal? The sketch should be declaring it.

The instance of the LiquidCrystal class should be an input to your library.

Here's a hint. The Arduino is programmed using C++.

I'm not sure if I understood you, but is because i need to include header.h in every source file that uses the instance of LiquidCrystal..

I declare the instance as extern in a header and then i define it normally in a sketch (source file). Then I include the header in every source file in order to make it visible for all the project (that worked with global variables like int, uint16_t, etc).

I think that it doesn't work with the instance of LiquidCrystal because it's an object, and maybe the declaration in header.h is calling the constructor and ultimately defining the object and not just declaring it.. hence, I'm defining the object twice.

But, I don't know what should I do to get a global instance of LiquidCrystal across multiple sketches :confused:

Header file:

extern LiquidCrystal lcd;

Source file:

[s]extern[/s] LiquidCrystal lcd(params...);

Edit: don't need extern in the source file.

oqibidipo:
Header file:

extern LiquidCrystal lcd;

Source file:

extern LiquidCrystal lcd(params...);

Ohh yeahh!! That works!

I guess I'm not understanding some things at all about the define/declare/extern thing

Thanks oqibidipo!

oqibidipo:
Source file:

extern LiquidCrystal lcd(params...);

... or just

LiquidCrystal lcd(params...);

oqibidipo:
... or just

LiquidCrystal lcd(params...);

I done it first using extern in the header and without using extern in the source, and then including the header in every source where i need to handle the LiquidCrystal object, but... that didn't work. The compiler gave me an error related with the redefinition of the object.

If I do as you write in this quote, the object only would be visible in the source where it is defined.. and i need it global.

Strangely what seems to work it's using extern twice.. In the header and then in the source, I don't know why.. but that works fine