Go Down

Topic: Compiling problem: undefined reference to `Servo::Servo() (Read 591 times) previous topic - next topic

Hawker001

Hello,

I want to extend the standard Servo. So I define a new class EServo. When I try to compile it, I get this  ]:) errormsg:
Code: [Select]
EServo\EServo.cpp.o: In function `EServo':
C:\arduino\arduino-1.0.1\libraries\EServo/EServo.cpp:12: undefined reference to `Servo::Servo()'


Where did it all go wrong  :(

my H-file (EServo.h) looks like this:
Code: [Select]
#ifndef ESERVO_H
#define ESERVO_H

#include "../Servo/Servo.h"

class EServo : public Servo
{
  public:
    // construction
    EServo(unsigned int);
    void update(void);

  private:
    unsigned int myPortNumber;
};

#endif


and the CPP-file (EServo.cpp) looks like this:
Code: [Select]
#include <Arduino.h>
#include "EServo.h"

EServo::EServo(unsigned int portNumber) :
  Servo(),    //line 12: ERROR: undefined reference to `Servo::Servo()
  myPortNumber(portNumber)
{
    //do something
}

void EServo::update(void)
{
    //update
}


Can somebody please HELP me???

Nick Gammon

Add this to your main sketch:

Code: [Select]

#include <Servo.h>


Also when including Servo.h inside EServo.h don't put in the path. Let the IDE work that out.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Hawker001

Unbelieveable, it compiles!

Thank you Nick, for your correct and fast answer!

But do I understand it? No  :(.

In the main sketch I included EServo.h:  #include <EServo.h>
and in EServo.h, the first thing I do is include Servo.h.

This should make no difference, or am I wrong? Or is it an Arduino IDE-issue?


Nick Gammon

The IDE copies files to a temporary folder. Your includes in the main sketch informs the copy process. Since they are copied to one spot you don't need the "../" part.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up