I have a base class Animal and a subclass Dog. I keep getting this error message from the terminal shown below.
Error message from terminal:
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Here are the header files included in both my base and subclass. My hunch tells me that there is something wrong with what type of header files I included in both my base and subclass. Are these right?
// base class
Animal.cc: #include "Animal.h",
Animal.h: nothing here
// subclass
Dog.cc:
#include "Animal.h", #include "Dog.h"
Dog.h: #include "Animal.h"
Also, I'll include my code for those who are curious
Animal.cpp
#include <cstdio>
#include <string>
#include "Animal.h"
using namespace std;
// define the virutal destructor because it is public
Animal::~Animal() throw() {}
Animal::Animal() throw() {
_name = "Madelyn";
_type = "Love";
_sound = "Thump";
}
Animal::Animal(const string& n, const string& t, const string& s) throw() {
_name = n;
_type = t;
_sound = s;
}
// define public functions of Animal
void Animal::speak() const throw() {
printf("%s the %s says %s", name().c_str(), type().c_str(), sound().c_str());
} // end of speak function
const string& Animal::name() const throw() {
return _name;
}// end of name function
const string& Animal::type() const throw() {
return _type;
} // end of type function
const string& Animal::sound() const throw() {
return _sound;
} // end of sound function
Animal.h
#ifndef ANIMAL_H_
#define ANIMAL_H_
#include <string>
using namespace std;
// Base class
class Animal {
private:
string _name;
string _type;
string _sound;
public:
Animal() throw();
Animal(const string& n, const string& t, const string& s) throw();
virtual ~Animal() throw();
const string& name() const throw();
const string& type() const throw();
const string& sound() const throw();
void speak() const throw();
}; // end of base class Animal
#endif
Dog.cpp
#include <cstdio>
#include <string>
#include "Animal.h"
#include "Dog.h"
using namespace std;
Dog:: Dog(const string& n) throw() : Animal(n, "dog", "woof") {
// nothing here
} // end of constructor
Dog:: Dog() throw() {
// nothing here
}
Dog::~Dog() throw() {
}
int Dog::walk() throw() {
return ++walked;
} // end of walk
Dog.h
#ifndef DOG_H_
#define DOG_H_
#include <string>
#include "Animal.h"
using namespace std;
// Dog class - derived from Animal
class Dog : public Animal {
int walked;
public:
Dog() throw();
virtual ~Dog() throw();
Dog(const string& n) throw();
int walk() throw();
};
#endif
Error message from terminal:
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Here are the header files included in both my base and subclass. My hunch tells me that there is something wrong with what type of header files I included in both my base and subclass. Are these right?
// base class
Animal.cc: #include "Animal.h",
Animal.h: nothing here
// subclass
Dog.cc:
#include "Animal.h", #include "Dog.h"
Dog.h: #include "Animal.h"
Also, I'll include my code for those who are curious
Animal.cpp
#include <cstdio>
#include <string>
#include "Animal.h"
using namespace std;
// define the virutal destructor because it is public
Animal::~Animal() throw() {}
Animal::Animal() throw() {
_name = "Madelyn";
_type = "Love";
_sound = "Thump";
}
Animal::Animal(const string& n, const string& t, const string& s) throw() {
_name = n;
_type = t;
_sound = s;
}
// define public functions of Animal
void Animal::speak() const throw() {
printf("%s the %s says %s", name().c_str(), type().c_str(), sound().c_str());
} // end of speak function
const string& Animal::name() const throw() {
return _name;
}// end of name function
const string& Animal::type() const throw() {
return _type;
} // end of type function
const string& Animal::sound() const throw() {
return _sound;
} // end of sound function
Animal.h
#ifndef ANIMAL_H_
#define ANIMAL_H_
#include <string>
using namespace std;
// Base class
class Animal {
private:
string _name;
string _type;
string _sound;
public:
Animal() throw();
Animal(const string& n, const string& t, const string& s) throw();
virtual ~Animal() throw();
const string& name() const throw();
const string& type() const throw();
const string& sound() const throw();
void speak() const throw();
}; // end of base class Animal
#endif
Dog.cpp
#include <cstdio>
#include <string>
#include "Animal.h"
#include "Dog.h"
using namespace std;
Dog:: Dog(const string& n) throw() : Animal(n, "dog", "woof") {
// nothing here
} // end of constructor
Dog:: Dog() throw() {
// nothing here
}
Dog::~Dog() throw() {
}
int Dog::walk() throw() {
return ++walked;
} // end of walk
Dog.h
#ifndef DOG_H_
#define DOG_H_
#include <string>
#include "Animal.h"
using namespace std;
// Dog class - derived from Animal
class Dog : public Animal {
int walked;
public:
Dog() throw();
virtual ~Dog() throw();
Dog(const string& n) throw();
int walk() throw();
};
#endif
Last edited: