0

I am quite new to C++ and hope that I don't bore you too much with my question.

I want to use an object of LiquidCrystal Class in another class called "Display_ManagerClass". I followed the instructions of the 2nd alternative in the following link:

Use object of other class within class

Unfortunately, I receive a linker error.

.ino-file:

#include "Licht_Manager.h"
#include "Display_Manager.h"
#include "Zeit_Manager.h"

LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);

void setup()
{

    Licht_Manager.init();
    Display_Manager.init(&lcd);
}


void loop()
{
    Display_Manager.showText("Hello", "World");
    while (1)
    {
        Licht_Manager.blink(1); 
    }
}

Display_Manager.h:

#ifndef _DISPLAY_MANAGER_h
#define _DISPLAY_MANAGER_h

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

#include <LiquidCrystal/src/LiquidCrystal.h>

class Display_ManagerClass
{
    protected:

    public:
        //void init();
        void init(LiquidCrystal* _p_lcd);
        void showText(String DisplayText1, String DisplayText2);
    private:
        LiquidCrystal* p_lcd;

};

extern Display_ManagerClass Display_Manager;

#endif

Display_Manager.cpp:

#include "Display_Manager.h"

void Display_ManagerClass::init(LiquidCrystal* _p_lcd)
{
    p_lcd = _p_lcd;
    p_lcd->clear();
}

void Display_ManagerClass::showText(String DisplayText1, String DisplayText2)
{
    p_lcd->clear();
    p_lcd->setCursor(0,0);
    p_lcd->print(DisplayText1);
    p_lcd->setCursor(0,1);
    p_lcd->print(DisplayText2);
}

Display_ManagerClass Display_Manager;

I receive the following errors:

Display_Manager.cpp.o:In function `Display_ManagerClass::init(LiquidCrystal*)
Display_Manager.cpp:clear()
Display_Manager.cpp.o:In function `Display_ManagerClass::showText(String, String)
Display_Manager.cpp:clear()
Display_Manager.cpp:setCursor(unsigned char, unsigned char)
Display_Manager.cpp:setCursor(unsigned char, unsigned char)
collect2.exe*:error: ld returned 1 exit status
Error creating .elf

I made sure that the correct directory of the library is set up in the project properties. The library also works in the normal way, but in combination with the class it doesn't.

I work with Atmel Studio 7 in combination with VisualMicro, Arduino IDE 1.6 and Arduino Uno.

Thank you in advance.

1 Answer 1

1

You must also include LiquidCrystal.h in your sketch. That way the IDE will know to include it in the list of files to compile and link with your sketch.

1
  • In the main .ino file is what Majenko is referring to. The IDE uses include directives there to know which libraries to include for linking purposes.
    – Nick Gammon
    Commented Apr 11, 2016 at 21:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.