undefined reference to LiquidCrystal::init()

When I try to compile any of the examples from the LiquidCrystal library I get this error:
undefined reference to LiquidCrystal::init()

I had this working a year ago, so has something changed either in arduino or the library since then?

I couldn´t find an answer to this in the forums.

hc

Which LiquidCrystal library are you using? Is it in the hardware/libraries directory of the version of Arduino that you're using? What example are you trying to compile?

I am using the 8 bit one, from the arduino tutorial, LiquidCrystal - Arduino Reference, and it is placed together with the other libraries in my arduino 11 folder.
Any of the examples included with the library give me the same error.

I noticed something else when starting the arduino software this morning, with the println_hello code loaded:
I get the error: error building library "LiquidCrystal", and then a long list in the console window:

LiquidCrystal.cpp:8: error: declaration of C function 'void pinMode(int, int)' conflicts with
/Applications/arduino-0011/hardware/cores/arduino/wiring.h:97: error: previous declaration 'void pinMode(uint8_t, uint8_t)' here
LiquidCrystal.cpp:9: error: declaration of C function 'void digitalWrite(int, int)' conflicts with
/Applications/arduino-0011/hardware/cores/arduino/wiring.h:98: error: previous declaration 'void digitalWrite(uint8_t, uint8_t)' here
LiquidCrystal.cpp:10: error: declaration of C function 'int digitalRead(int)' conflicts with
/Applications/arduino-0011/hardware/cores/arduino/wiring.h:99: error: previous declaration 'int digitalRead(uint8_t)' here

I also notice that I dont get the magic .o file, which means the library never gets compiled?

I tried cheating by removing the wiring.h file but that just generated an even longer list of errors.

In liquidcrystal.cpp, remove the following lines that should not have been put in that file:

extern void pinMode(int, int);
extern void digitalWrite(int, int);
extern int digitalRead(int);
extern void portMode(uint8_t, uint8_t);
extern void portWrite(uint8_t, uint8_t);
extern uint8_t portRead(uint8_t);

in the current Arduino distrubitions these functions are defined wiring.h and have different parameters, which is what causes the error message.

thanks, that solved it!
maybe someone should update the library, or at least write a note about it in the tutorial?

I have modified the library but I am not sure how I get an account to modify the tutorial pages (the playground login does not seem to work).

Arduino 0012 will have an LiquidCrystal library built in, so I'll remove that tutorial when it comes out. (Or at least update it to working code. :slight_smile: )

thx for the fast reply though. I removed those lines, but after opening, I still get a lot of errors and for me not locateable. =(

modified LiquidCrystal.cpp

#include "LiquidCrystal.h"
extern "C" {
  #include <stdio.h>
  #include <string.h>
  #include <inttypes.h>
  #include "WConstants.h"


}
/*
no room for following defines:

#define right 0x1C
#define left 0x18
#define hm 0x02
*/
#define init1 0x30
#define init2 0x0E
#define init3 0x06
#define init4 0x80
#define clr 0x01

int RS = 12; 
int RW = 11;
int Enable = 2;
int DB[] = {3, 4, 5, 6, 7, 8, 9, 10};

void LiquidCrystal::commandWrite(int value) {
 int i = 0;
 digitalWrite(RS, LOW);
 digitalWrite(RW, LOW);
 for (i=DB[0]; i <= DB[7]; i++) {
   digitalWrite(i,value & 01);
   value >>= 1;
 }
 digitalWrite(Enable,LOW);
 delayMicroseconds(1);
 // send a pulse to enable
 digitalWrite(Enable,HIGH);
 delayMicroseconds(1);  
 digitalWrite(Enable,LOW);
 delayMicroseconds(2);  
 delay(10);
}

void LiquidCrystal::init () {
 int i = 0;
 for (i=Enable; i <= RS; i++) {
   pinMode(i,OUTPUT);
 }
 delay(100);
 // initiatize lcd after a short pause
 // needed by the LCDs controller
 commandWrite(init1);  
                         
 delay(64);                      
 commandWrite(init1);  
                         
 delay(50);                      
 commandWrite(init1);  
 
 delay(50);                     
 
commandWrite(init2);  // display control:
                         // turn display on, cursor on, no blinking
 delay(20);                      
 commandWrite(init3);  // entry mode set: 06
                         // increment automatically, display shift, right shift
 delay(20);                      
                       
 commandWrite(clr);  // clear display, set cursor position to zero  
 delay(100);                      
 commandWrite(init4);  // 
                         // 
 delay(20);
}

LiquidCrystal::LiquidCrystal()
{
  
}

void LiquidCrystal::print(int value) {
 // poll all the pins
 int i = 0;
 digitalWrite(RS, HIGH);
 digitalWrite(RW, LOW);
 for (i=DB[0]; i <= DB[7]; i++) {
   digitalWrite(i,value & 01);
   value >>= 1;
 }
 digitalWrite(Enable,LOW);
 delayMicroseconds(1);
 // send a pulse to enable
 digitalWrite(Enable,HIGH);
 delayMicroseconds(1);
 digitalWrite(Enable,LOW);
 delay(1);  // pause 1 ms according to datasheet
}

void LiquidCrystal::printIn(char value[]) {
      uint8_t i;
      
      for (i=0;i<strlen(value);i++){
            print(value[i]);
      }
}

void LiquidCrystal::clear(){
 commandWrite(clr); //clear screen 
}

/* 
//No room for the following functions:

void LiquidCrystal::home(){
  commandWrite(hm);  // set cursor position to zero
}

void LiquidCrystal::setCursor(int index){
  //0-79, index for one line display, 8 bit mode
  //0-39 and 64-103 for lines one and two of two line display, not implemented yet
  int cmd = 128+index;
  commandWrite(cmd);
}

void LiquidCrystal::shiftDisplayLeft(){ 
  commandWrite(left);
}

void LiquidCrystal::shiftDisplayRight(){
  commandWrite(right);
}
*/

Some of the error messages

LiquidCrystal.cpp:166:1: warning: null character(s) ignored
LiquidCrystal.cpp:167:1: warning: null character(s) ignored
LiquidCrystal.cpp:167:5: warning: null character(s) ignored
LiquidCrystal.cpp:167:7: warning: null character(s) ignored
LiquidCrystal.cpp:167:11: warning: null character(s) ignored
LiquidCrystal.cpp:167:13: warning: null character(s) ignored
LiquidCrystal.cpp:167:15: warning: null character(s) ignored
LiquidCrystal.cpp:167:17: warning: null character(s) ignored
LiquidCrystal.cpp:167:21: warning: null character(s) ignored
LiquidCrystal.cpp:167:23: warning: null character(s) ignored
LiquidCrystal.cpp:167:25: warning: null character(s) ignored
LiquidCrystal.cpp:167:29: warning: null character(s) ignored
LiquidCrystal.cpp:167:31: warning: null character(s) ignored
LiquidCrystal.cpp:167:33: warning: null character(s) ignored
LiquidCrystal.cpp:167:37: warning: null character(s) ignored
LiquidCrystal.cpp:167:39: warning: null character(s) ignored
LiquidCrystal.cpp:167:41: warning: null character(s) ignored
LiquidCrystal.cpp:167:43: warning: null character(s) ignored
LiquidCrystal.cpp:168:1: warning: null character(s) ignored
LiquidCrystal.cpp:169:1: warning: null character(s) ignored
LiquidCrystal.cpp:169:5: warning: null character(s) ignored
LiquidCrystal.cpp:169:7: warning: null character(s) ignored
LiquidCrystal.cpp:169:9: warning: null character(s) ignored
LiquidCrystal.cpp:169:13: warning: null character(s) ignored
LiquidCrystal.cpp:169:17: warning: null character(s) ignored
LiquidCrystal.cpp:169:21: warning: null character(s) ignored
LiquidCrystal.cpp:169:23: warning: null character(s) ignored
LiquidCrystal.cpp:170:1: warning: null character(s) ignored
..... (AND SO ON).....
LiquidCrystal.cpp:1: error: 'i' does not name a type
LiquidCrystal.cpp:19: error: expected unqualified-id before '/' token
LiquidCrystal.cpp:47: error: 'i' does not name a type
LiquidCrystal.cpp:49: error: 'i' does not name a type
LiquidCrystal.cpp:51: error: 'i' does not name a type
LiquidCrystal.cpp:55: error: 'v' does not name a type
LiquidCrystal.cpp:217: error: 'v' does not name a type
LiquidCrystal.cpp:225: error: expected unqualified-id before '/' token
LiquidCrystal.cpp:239: error: 'v' does not name a type

thx for the fast reply though. I removed those lines, but after opening, I still get a lot of errors and for me not locateable. =(

double post, see this tread: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1216178077/4#4