我有 3 个文件:Triliza.h、Triliza.cpp 和 Game.cpp。这是我的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
这是我的主文件: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;
}
有错误输出:
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
所以我想当我尝试将每个文件一起导入时有问题。谁能指出我正确的方法。谢谢
编辑:更改后出现另一个错误。
make: *** No rule to make target `Trizilla.o', needed by `prog'. Stop.
感谢所有回复。我知道了。因为在 Triliza 中有拼写错误