calling libraries from both sketches and other libraries

Hi all;
I have searched thru the forum and have not been able to find a topic like mine to get info from so I thought I would just ask directly.
I am using an ADAFruit LCD shield with buttons in a project. I would like to access the LCD library from both my main sketch and from a library.
Starting with the sketch and main loop;

// include the library code:
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>
#include <math.h>
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();

Creating the instance of the shield with the name lcd.

The main loop looks for buttons on the shield:

void loop (){
while (lcd.readButtons() != 0) { //idle loop no button pressed
thisButton = lcd.readButtons(); //get buttons from I2C
while (lcd.readButtons() == thisButton) {} //wait for button release
do_Buttons(thisButton); //process button press
}
//display measure values
if (updateFlag == true && context >= measOperate){
//Serial.println (“ISR is Updating”);
updateFlag = false; //reset flag until next display update ISR
lcd.home(); //set LCD cursor to upper left
ADC1.updateMeasure (thisCh->measUnit, thisCh->measDisp, thisCh->srcMde, &measVolt1,
&measCurrent1);
lcd.print(thisCh->measDisp);
lcd.setCursor (thisCol,thisRow); //restores cursor after updating measure display
}
}

do_Buttons is a state machine that processes the buttons and displays status, etc. When all the code is included in the sketch, it works fine. I would like to port do_Buttons to another library, but I still need to use the ADAFruit shield library in that library. I have tried creating another instance of the shield in a cpp file;

#include “Arduino.h”
#include “SMUI.h”
Adafruit_RGBLCDShield smulcd = Adafruit_RGBLCDShield();

and a small test routine;

void putCursor (byte col, byte row)
{
thisCol = col;
** thisRow = row;**
smulcd.setCursor (col,row);
}
with thisCol and thisRow declared in the header file;

#ifndef SMUI_h_
#define SMUI_h_
#include <SourceMeter.h>
#include “Arduino.h”
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>

/********* Some constants and variables here *********************************/
volatile byte thisRow; //used for putcursor - volatile because used in ISR
volatile byte thisCol; //to restore the cursor

void putCursor (byte col, byte row);
#endif

But I keep getting multiple definition errors:

Arduino: 1.8.1 (Windows 8), Board: “Arduino Pro or Pro Mini, ATmega328 (3.3V, 8 MHz)”
libraries\SourceMeter\SMUI.cpp.o (symbol from plugin): In function smulcd': (.text+0x0): multiple definition of thisCol’
sketch\Sourcemeter2t.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries\SourceMeter\SMUI.cpp.o (symbol from plugin): In function smulcd': (.text+0x0): multiple definition of thisRow’
sketch\Sourcemeter2t.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status

Is there any way to use a library in both the main sketch and other libraries? Sort of like declaring a library as extern in the sketch? Or is it better practice to just re-write the main loop to call all the shield routines from my new library?

Does your library have include guards?

Yes in the header file;

#ifndef SMUI_h_
#define SMUI_h_
#include <SourceMeter.h>
#include “Arduino.h”
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>
.
.
.
#endif

Do not create objects in header files that are included in separate compilation units. This will lead to multiple definition errors. ;)

volatile byte thisRow;                 //used for putcursor - volatile because used in ISR
volatile byte thisCol;                 //to restore the cursor

By the way, why are these variables volatile?

Which ISR is going to acces them?

Thank you, I did not know that, but it makes sense. Actually, in looking closer it turns out that the ISR doesn't actually use these variables, so I guess they don't need to be volatile?