我生命中的第一次,我必须在大项目上使用Makefile(它使用ncurses
)。这是我的Makefile:
PROGRAM=go
CC=g++
CFLAGS=-std=c++11 -Wall -pedantic -Wextra -g -Wno-long-long -O0 -ggdb
LCUR=-lncurses
all: compile
run: compile
./$(PROGRAM)
compile: $(PROGRAM)
$(PROGRAM): objs/main.o objs/game.o
$(CC) $(CFLAGS) $^ -o $@ $(LCUR)
objs/main.o: src/main.cpp | objs
$(CC) $(CFLAGS) -c $< -o $@ $(LCUR)
objs/game.o: src/Token.cpp src/GoSocket.cpp src/GoSerializer.cpp src/GoMenu.cpp src/Points.cpp src/Player.cpp src/LocalPlayer.cpp src/LanPlayer.cpp src/RandomAIPlayer.cpp src/SatisfactoryAIPlayer.cpp src/GoRulesChecker.cpp src/GoLanGame.cpp src/GameBoard.cpp src/Game.cpp | objs
$(CC) $(CFLAGS) -c $< -o $@ $(LCUR)
objs:
mkdir objs
clean:
rm -rf $(PROGRAM) objs/ doc/ 2>/dev/null
我一切都很顺利,直到$(PROGRAM)
最终链接我遇到错误之墙:
~/ClionProjects/gj $ make compile
mkdir objs
g++ -std=c++11 -Wall -pedantic -Wextra -g -Wno-long-long -O0 -ggdb -c src/main.cpp -o objs/main.o -lncurses
In file included from src/main.cpp:3:0:
src/GoMenu.h:49:5: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
};
^
src/GoMenu.h:49:5: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
src/GoMenu.h:49:5: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
src/GoMenu.h:49:5: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
src/GoMenu.h:49:5: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
src/GoMenu.h:49:5: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
src/GoMenu.h:49:5: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
g++ -std=c++11 -Wall -pedantic -Wextra -g -Wno-long-long -O0 -ggdb -c src/Token.cpp -o objs/game.o -lncurses
g++ -std=c++11 -Wall -pedantic -Wextra -g -Wno-long-long -O0 -ggdb objs/main.o objs/game.o -o go -lncurses
objs/main.o: In function `announceScore(Player*, Player*)':
/home/mint/ClionProjects/gj/src/main.cpp:25: undefined reference to `GoMenu::GoMenu()'
/home/mint/ClionProjects/gj/src/main.cpp:39: undefined reference to `GoMenu::showMessage(std::string const&) const'
objs/main.o: In function `main':
/home/mint/ClionProjects/gj/src/main.cpp:51: undefined reference to `GoMenu::GoMenu()'
/home/mint/ClionProjects/gj/src/main.cpp:52: undefined reference to `GoMenu::show()'
/home/mint/ClionProjects/gj/src/main.cpp:53: undefined reference to `GoMenu::showMessage(std::string const&) const'
/home/mint/ClionProjects/gj/src/main.cpp:54: undefined reference to `GoMenu::choose() const'
/home/mint/ClionProjects/gj/src/main.cpp:59: undefined reference to `GameBoard::GameBoard(int, int)'
/home/mint/ClionProjects/gj/src/main.cpp:60: undefined reference to `LocalPlayer::LocalPlayer(int, int, GameBoard&)'
/home/mint/ClionProjects/gj/src/main.cpp:61: undefined reference to `LocalPlayer::LocalPlayer(int, int, GameBoard&)'
/home/mint/ClionProjects/gj/src/main.cpp:62: undefined reference to `Game::Game(Player&, Player&, GameBoard&)'
/home/mint/ClionProjects/gj/src/main.cpp:69: undefined reference to `GoMenu::showMessage(std::string const&) const'
/home/mint/ClionProjects/gj/src/main.cpp:73: undefined reference to `GoMenu::showMessage(std::string const&) const'
/home/mint/ClionProjects/gj/src/main.cpp:82: undefined reference to `GoMenu::showMessage(std::string const&) const'
/home/mint/ClionProjects/gj/src/main.cpp:86: undefined reference to `GoSocket::GoSocket(std::string const&, int)'
/home/mint/ClionProjects/gj/src/main.cpp:88: undefined reference to `GoSocket::tryConnect()'
/home/mint/ClionProjects/gj/src/main.cpp:94: undefined reference to `GoSocket::readMessage() const'
/home/mint/ClionProjects/gj/src/main.cpp:104: undefined reference to `GameBoard::GameBoard(int, int)'
/home/mint/ClionProjects/gj/src/main.cpp:105: undefined reference to `GameBoard::render()'
/home/mint/ClionProjects/gj/src/main.cpp:106: undefined reference to `GoLanGame::GoLanGame(GameBoard&, GoSocket&, int)'
/home/mint/ClionProjects/gj/src/main.cpp:109: undefined reference to `GoLanGame::loop()'
/home/mint/ClionProjects/gj/src/main.cpp:108: undefined reference to `GoLanGame::isRunning()'
/home/mint/ClionProjects/gj/src/main.cpp:109: undefined reference to `GoSocket::~GoSocket()'
/home/mint/ClionProjects/gj/src/main.cpp:126: undefined reference to `GameBoard::GameBoard(int, int)'
/home/mint/ClionProjects/gj/src/main.cpp:127: undefined reference to `SatisfactoryAIPlayer::SatisfactoryAIPlayer(int, int, GameBoard&)'
/home/mint/ClionProjects/gj/src/main.cpp:128: undefined reference to `GameBoard::setBlackSurrender(bool)'
/home/mint/ClionProjects/gj/src/main.cpp:129: undefined reference to `LocalPlayer::LocalPlayer(int, int, GameBoard&)'
/home/mint/ClionProjects/gj/src/main.cpp:130: undefined reference to `Game::Game(Player&, Player&, GameBoard&)'
/home/mint/ClionProjects/gj/src/main.cpp:135: undefined reference to `GameBoard::GameBoard(int, int)'
/home/mint/ClionProjects/gj/src/main.cpp:136: undefined reference to `RandomAIPlayer::RandomAIPlayer(int, int, GameBoard&)'
/home/mint/ClionProjects/gj/src/main.cpp:137: undefined reference to `GameBoard::setBlackSurrender(bool)'
/home/mint/ClionProjects/gj/src/main.cpp:138: undefined reference to `LocalPlayer::LocalPlayer(int, int, GameBoard&)'
/home/mint/ClionProjects/gj/src/main.cpp:139: undefined reference to `Game::Game(Player&, Player&, GameBoard&)'
/home/mint/ClionProjects/gj/src/main.cpp:151: undefined reference to `GoMenu::showMessage(std::string const&) const'
/home/mint/ClionProjects/gj/src/main.cpp:158: undefined reference to `GoSerializer::Deserialize(std::string const&, int*, int*) const'
/home/mint/ClionProjects/gj/src/main.cpp:161: undefined reference to `GoMenu::showMessage(std::string const&) const'
/home/mint/ClionProjects/gj/src/main.cpp:173: undefined reference to `GameBoard::GameBoard(int, int, int***)'
/home/mint/ClionProjects/gj/src/main.cpp:174: undefined reference to `LocalPlayer::LocalPlayer(int, int, GameBoard&)'
/home/mint/ClionProjects/gj/src/main.cpp:175: undefined reference to `LocalPlayer::LocalPlayer(int, int, GameBoard&)'
/home/mint/ClionProjects/gj/src/main.cpp:176: undefined reference to `Game::Game(Player&, Player&, GameBoard&)'
/home/mint/ClionProjects/gj/src/main.cpp:184: undefined reference to `GameBoard::GameBoard(int, int)'
/home/mint/ClionProjects/gj/src/main.cpp:185: undefined reference to `GoSocket::GoSocket(std::string const&, int)'
/home/mint/ClionProjects/gj/src/main.cpp:186: undefined reference to `GoSocket::start()'
/home/mint/ClionProjects/gj/src/main.cpp:187: undefined reference to `GoMenu::showMessage(std::string const&) const'
/home/mint/ClionProjects/gj/src/main.cpp:188: undefined reference to `GoSocket::waitForClient()'
/home/mint/ClionProjects/gj/src/main.cpp:191: undefined reference to `GameBoard::getRows()'
/home/mint/ClionProjects/gj/src/main.cpp:193: undefined reference to `GameBoard::getCols()'
/home/mint/ClionProjects/gj/src/main.cpp:196: undefined reference to `GoSocket::writeMessage(std::string const&)'
/home/mint/ClionProjects/gj/src/main.cpp:198: undefined reference to `LocalPlayer::LocalPlayer(int, int, GameBoard&)'
/home/mint/ClionProjects/gj/src/main.cpp:199: undefined reference to `LanPlayer::LanPlayer(int, int, GoSocket&)'
/home/mint/ClionProjects/gj/src/main.cpp:200: undefined reference to `Game::Game(Player&, Player&, GameBoard&)'
/home/mint/ClionProjects/gj/src/main.cpp:201: undefined reference to `Game::setNetwork(bool)'
/home/mint/ClionProjects/gj/src/main.cpp:202: undefined reference to `Game::setSocket(GoSocket*)'
/home/mint/ClionProjects/gj/src/main.cpp:202: undefined reference to `GoSocket::~GoSocket()'
/home/mint/ClionProjects/gj/src/main.cpp:205: undefined reference to `GameBoard::render()'
/home/mint/ClionProjects/gj/src/main.cpp:217: undefined reference to `Game::doLogic()'
/home/mint/ClionProjects/gj/src/main.cpp:219: undefined reference to `GoRulesChecker::GoRulesChecker(GameBoard&)'
/home/mint/ClionProjects/gj/src/main.cpp:221: undefined reference to `GameBoard::getArray()'
/home/mint/ClionProjects/gj/src/main.cpp:221: undefined reference to `GoRulesChecker::checkRules(int***, std::list<Token, std::allocator<Token> >&)'
/home/mint/ClionProjects/gj/src/main.cpp:222: undefined reference to `GameBoard::render(std::list<Token, std::allocator<Token> >*)'
/home/mint/ClionProjects/gj/src/main.cpp:224: undefined reference to `GameBoard::WhiteSurrender()'
/home/mint/ClionProjects/gj/src/main.cpp:224: undefined reference to `GameBoard::BlackSurreder()'
/home/mint/ClionProjects/gj/src/main.cpp:237: undefined reference to `Game::getTurn() const'
/home/mint/ClionProjects/gj/src/main.cpp:241: undefined reference to `Game::getTurn() const'
/home/mint/ClionProjects/gj/src/main.cpp:215: undefined reference to `Game::isRunning()'
/home/mint/ClionProjects/gj/src/main.cpp:251: undefined reference to `GameBoard::~GameBoard()'
/home/mint/ClionProjects/gj/src/main.cpp:259: undefined reference to `Game::~Game()'
/home/mint/ClionProjects/gj/src/main.cpp:109: undefined reference to `GoSocket::~GoSocket()'
/home/mint/ClionProjects/gj/src/main.cpp:202: undefined reference to `GoSocket::~GoSocket()'
collect2: error: ld returned 1 exit status
make: *** [go] Error 1
你能告诉我我做错了吗?