I have 3 files: Triliza.h, Triliza.cpp and Game.cpp.
This is my makefile
CC = g++
prog: Game.o
$(CC) Game.o -Wall -Werror -pedantic -o Triliza
Game.o: Game.cpp Triliza.h
$(CC) -Wall -Werror -pedantic -c Game.cpp
Triliza.o: Triliza.cpp Triliza.h
$(CC) -Wall -Werror -pedantic -c Triliza.cpp
This is my main file: Game.cpp
#include <iostream>
using namespace std;
#include "Triliza.h"
Triliza *triliza;
int main(int argc, char* argv[])
{
while (1)
{
triliza = new Triliza();
triliza->verifyFirstPlayer();
triliza->loop();
if (!triliza->playAgain())
break;
}
return 0;
}
There is a error output:
g++ Game.o -Wall -Werror -pedantic -o Triliza
Undefined symbols:
"Triliza::Triliza()", referenced from:
_main in Game.o
"Triliza::verifyFirstPlayer()", referenced from:
_main in Game.o
"Triliza::loop()", referenced from:
_main in Game.o
"Triliza::playAgain()", referenced from:
_main in Game.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [prog] Error 1
So I suppose there are something wrong when I try to import each file together. Could anyone point me a correct way. Thanks
Edit: after changing there is another error came out.
make: *** No rule to make target `Trizilla.o', needed by `prog'. Stop.
Thanks for all replies. I got it. because there is misspelling in Triliza
You’re not linking in Triliza.o when the executable is built due to a dependency issue. Change the prog target as follows: