tiny core (attiny85) and HellowWorld_SR (2 wire lcd) return conflict error

If I take the example from LiquidCrystal to utilize the 2 wire interface and make the only change to the pin definitions:
LiquidCrystal_SR lcd(1,0,TWO_WIRE);

the compiler gives in wire.h
error: conflicting return type specified for 'virtual size_t TwoWire::write(const unit8_t*, size_t)'
and print.h
error:overrriding 'virtual void Print::write(const unit8_t*, sizet)'

I attempted to make it return a value but it seemed to make things worse.
Can anyone suggest an appropriate fix?

BTW, how does one cut the error messages from the IDE (in winxp) for pasting here?
thanks much-john

Where did you get the LiquidCrystal_SR library?

BTW, how does one cut the error messages from the IDE (in winxp) for pasting here?

• Click in the Status Window to give it the focus

• Hold Ctrl then press A

• Hold Ctrl then press C

• Paste into a reply; please use
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags

I attempted to make it return a value but it seemed to make things worse.
Can anyone suggest an appropriate fix?

Sure. Do it right.

What attempt did you make? Which file(s) did you change? You need to make three changes, to two files.

Greetings Coding Badly,
I'm using "new liquidcrystal library by fransciso" here:
https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home
It came from a link that has the schematics here:
http://code.google.com/p/arduinoshiftreglcd/
I had forgotten the same titled library replaced the standard LiquidCrystal library. I'm using the "diode resistor and gate" version (not I2C) and it worked with a nano.

Thanks for your quick reply - I wish I could get back to my project now, but can only work on it sporatically.

@PaulS
hmmm, I'l have a closer look at that - I made 2 changes in 2 files (.cpp .h). I'll repost with more info this evening.

Here's the changes made to tiny core's print.cpp and print.h:

/* default implementation: may be overridden */
//void Print::write(const char *str)
//{
//  while (*str)
//    write(*str++);
//}
//jc100 above is original, below from arduino
size_t Print::write(const char *str)
{
  size_t n = 0;
  while (*str){
    write(*str++);
  }
  return n;
}

/* default implementation: may be overridden */
//void Print::write(const uint8_t *buffer, size_t size)  
//  while (size--)
//    write(*buffer++);
//}
//jc100 below is from arduino, above original tiny
size_t Print::write(const uint8_t *buffer, size_t size)
{
  size_t n = 0;
  while (size--) {
    n += write(*buffer++);
  }
  return n;
}
  public:
    virtual size_t write(uint8_t) = 0;
//    virtual void write(const char *str);
//    virtual void write(const uint8_t *buffer, size_t size); 
//jc100 below is from working arduino file, above is original
    size_t write(const char *str) { return write((const uint8_t *)str, strlen(str)); }
    virtual size_t write(const uint8_t *buffer, size_t size);

here's the program:

//#include <Wire.h>
#include <LCD.h>  // franscisco's example? instead of wire.h
#include <LiquidCrystal_SR.h>

LiquidCrystal_SR iLCD(1,0);

void setup(){

  iLCD.begin(16,2);               // initialize the lcd
  iLCD.home ();                   // go home
  iLCD.print("LiquidCrystal_SR");
}

void loop(){
}

and here's the compile result:

C:\Documents and Settings\H1\My Documents\Downloads\arduino-1.0.1-windows\arduino-1.0.1\hardware\tiny\cores\tiny\Print.cpp:39: error: redefinition of 'size_t Print::write(const char*)'
C:\Documents and Settings\H1\My Documents\Downloads\arduino-1.0.1-windows\arduino-1.0.1\hardware\tiny\cores\tiny\/Print.h:77: error: 'size_t Print::write(const char*)' previously defined here

After using #include <lcd.h> instead of <wire.h> per the fransciso's example
(https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/schematics#!non-latching-shift-register)
a lot of errors were eliminated - I pared down the HelloWorld_SR to the basics with that change and attempted to follow suggestions here and by Nick Gammon here:
Arduino Forum

Coding Badly, I appreciate your desire to pare code to a minimum, but from what I can tell, haven't the write routines been changed (somewhere between arduino 0022 and 1.0.1) to return a value?
ie: from LCD.h
#if (ARDUINO < 100)
virtual void write(uint8_t value);
#else
virtual size_t write(uint8_t value);
#endif

suggestions? - john

size_t write(const char *str) { return write((const uint8_t *)str, strlen(str))

...

size_t Print::write(const char *str)
{
  size_t n = 0;
  while (*str){
    write(*str++);
  }
  return n;
}

You have two implementations of write. Don't you?

size_t Print::write(const char *str)
{
  size_t n = 0;
  while (*str){
    write(*str++);
  }
  return n;
}

And what value will n have? The value returned is supposed to be the number of bytes written to the serial port.

jcobble:
Coding Badly, I appreciate your desire to pare code to a minimum, ...

It has less to do with paring and more to do with laziness.

...but from what I can tell, haven't the write routines been changed (somewhere between arduino 0022 and 1.0.1) to return a value?

Yes.

From the stuff above, it looks like you are close to having the problem knocked out. Did you get it working?

Yeah! Solved!
Just logging back in to post the results - Coding Badly I don't consider your voluminous efforts as any indication of laziness :stuck_out_tongue: Thanks for the tiny core and for the cut an paste answer! I hope others will find the 2 wire lcd solution equally beneficial to the low pin count tinys - no I2C complexity, 25cent part, no "piggyback serial-to-lcd" micro w/code, programming, crystal and cost to contend with.

Yes Nick, that line in the header file gave me pause, but as it was apparently working for a nano compile in the arduino toolchain, I just left it. Thanks much for the tip. As I was just tossing darts to get the compile errors down, I ignored code operational correctness at that go around.

That error being corrected, left another error having to do with _cxa_pure_virtual which is solved by copying the new.cpp new.h files over to the tiny toolchain.

so for the program example shown above, the summary of changes are below:

changes to print.cpp============================

/* default implementation: may be overridden */
//void Print::write(const char *str)
//{
//  while (*str)
//    write(*str++);
//}
//jc100 above is original, below from arduino
// tiny core needs new.cpp, new.h to resolve error:LiquidCrystal\LCD.cpp.o:(.rodata._ZTV3LCD+0xe): undefined reference //to`__cxa_pure_virtual'
size_t Print::write(const char *str)
{
  size_t n = 0;
  while (*str){
    write(*str++);
    n++;
  }
  return n;
}

/* default implementation: may be overridden */
//void Print::write(const uint8_t *buffer, size_t size)  
//  while (size--)
//    write(*buffer++);
//}
//jc100 below is from arduino, above original tiny
size_t Print::write(const uint8_t *buffer, size_t size)
{
  size_t n = 0;
  while (size--) {
    n += write(*buffer++);
  }
  return n;
}



changes to print.h==============
 public:
    virtual size_t write(uint8_t) = 0;
//    virtual void write(const char *str);
//    virtual void write(const uint8_t *buffer, size_t size); 
//jc100 below is from working arduino file, above is original
//    size_t write(const char *str) { return write((const uint8_t *)str, strlen(str)); }
    size_t write(const char *str);
    virtual size_t write(const uint8_t *buffer, size_t size);


copy new.h, new.cpp from arduino core to the tiny core ===================

eg: from here:
C:\Documents and Settings\H1\My Documents\Downloads\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\arduino
to here:
C:\Documents and Settings\H1\My Documents\Downloads\arduino-1.0.1-windows\arduino-1.0.1\hardware\tiny\cores\tiny

Oh, and a big thanks to the ShiftRegisterLCD contributor and Franscisco - for a fine consolidated library and especially for helping us navigate the changing world of arduino!

Thank you for the follow-up.

jcobble:
That error being corrected, left another error having to do with _cxa_pure_virtual which is solved by copying the new.cpp new.h files over to the tiny toolchain.

Someone foolishly left a pure virtual function in their code; a very bad choice.

I suggest eliminating the problem at the source. If the missing function is ever called your sketch will "terminate". Debugging that is a nightmare.

Though this is getting rather esoteric, I think we are ok.
Part of the reason why I was "spinning my wheels" eliminating that _cxa_pure_virtual error was because I couldn't find it being called (doing a global search).
from the (non-verbose) output:
error:LiquidCrystal\LCD.cpp.o:(.rodata._ZTV3LCD+0xe): undefined reference to`__cxa_pure_virtual'
it appeared to be during the object code creation steps. and from the link at the top of the new.h file
(http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=59453 )

"Code:

void __cxa_pure_virtual(void) {};

This function is never called in normal operation. The only time this function may get called is if the application calls a virtual function while the object is still being created, which gives undefined behavior. So implementation is not very important for us. "

And in toying with other fixes, it always appeared to occur in ".o" files - so I think we're fine.

and FWIW, Arduino being somewhat new to me, I just came across this "summary" that others might find helpful:
Arduino 1.0 is Out: Here's What You Need To Know