Nov 19, 2021 at 7:36am UTC
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;
}
Nov 19, 2021 at 8:03am UTC
Is dog.cpp part of the project ?
Nov 19, 2021 at 4:20pm UTC
Each file is a part of the project. The files are main.cpp, Dog.cpp, and Dog.h
Nov 19, 2021 at 9:35pm UTC
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 Nov 19, 2021 at 9:36pm UTC