Pages: [1]   Go Down
Author Topic: Compiling problem: undefined reference to `Servo::Servo()  (Read 557 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I want to extend the standard Servo. So I define a new class EServo. When I try to compile it, I get this  smiley-evil errormsg:
Code:
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  smiley-sad

my H-file (EServo.h) looks like this:
Code:
#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:
#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???
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 502
Posts: 19086
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Add this to your main sketch:

Code:
#include <Servo.h>

Also when including Servo.h inside EServo.h don't put in the path. Let the IDE work that out.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Unbelieveable, it compiles!

Thank you Nick, for your correct and fast answer!

But do I understand it? No  smiley-sad.

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?

Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 502
Posts: 19086
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Pages: [1]   Go Up
Jump to: