Header, implementation and main files, undefined reference to constructor

Hello, I am really confused with what the issue is here with my code. It's a simple example, but I keep getting the following error:

C:\Users\User\AppData\Local\Temp\ccE9oMcC.o main.cpp:(.text+0x15): undefined reference to `Dog::Dog()'

It's a really simple program, so what could possibly be causing the error?
Side note, I am using Dev C++


// File: Dog.h

#ifndef DOG_H
#define DOG_H

class Dog
{
public:
Dog(); //constructor

};
#endif




// File: Dog.cpp

#include "Dog.h"
#include <iostream>
using namespace std;

Dog::Dog()
{
cout << "Woof!";
}




// main.cpp

#include <iostream>
#include "Dog.h"

using namespace std;

int main(){

Dog d;

return 0;
}

Is dog.cpp part of the project ?
Each file is a part of the project. The files are main.cpp, Dog.cpp, and Dog.h
Can you show what compilation commands are generated? Do you see a Dog.o file ever generated?
The reason we don't think that Dog.cpp is being compiled is because that's where the unfound reference to Dog's ctor is.

Does it build if you manually run your own command, e.g.
g++ -Wall dog.cpp main.cpp -o dog
Last edited on
Topic archived. No new replies allowed.