我不断出错

make: *** No rule to make target `all'.  Stop.

我确信我的makefile可以完美运行,因为我确实在终端上运行了它,并且一切正常。但是,当我尝试通过创建一个空的Makefile项目将所有内容导入eclispe时,无法编译该程序。那我在Eclipse配置中错过了什么吗?

无论如何,这是我的makefile,请看一看并纠正我。谢谢
CC = g++
prog: legrec.o game.o board.o piece.o
    $(CC) legrec.o game.o board.o piece.o -Wall -Werror -pedantic -o legrec
legrec.o: legrec.cpp game.h
    $(CC) -Wall -Werror -pedantic -c legrec.cpp
game.o: game.cpp game.h board.h piece.h move.h player.h
    $(CC) -Wall -Werror -pedantic -c game.cpp
board.o: board.cpp board.h piece.h move.h player.h
    $(CC) -Wall -Werror -pedantic -c board.cpp
piece.o: piece.cpp piece.h board.h move.h player.h
    $(CC) -Wall -Werror -pedantic -c piece.cpp

编辑:感谢所有答复,我确实将第一行更改为all:legrec,并且以前的错误消息不见了,但是又出现了另一个错误
     cc   legrec.o   -o legrec
 Undefined symbols for architecture x86_64:
    "game::game()", referenced from:
         _main in legrec.o
    "game::printMenu()", referenced from:
         _main in legrec.o
    "game::printBoard()", referenced from:
         _main in legrec.o
    "game::nextMove()", referenced from:
         _main in legrec.o
    "game::ended()", referenced from:
         _main in legrec.o
    "game::printWinner()", referenced from:
         _main in legrec.o
    "game::~game()", referenced from:
         _main in legrec.o
    "std::terminate()", referenced from:
         _main in legrec.o
    "std::ios_base::Init::Init()", referenced from:
         __static_initialization_and_destruction_0(int, int)in legrec.o
    "std::ios_base::Init::~Init()", referenced from:
         ___tcf_0 in legrec.o
    "___gxx_personality_v0", referenced from:
         Dwarf Exception Unwind Info (__eh_frame) in legrec.o
 ld: symbol(s) not found for architecture x86_64
 collect2: ld returned 1 exit status
 make: *** [legrec] Error 1

我只是不明白为什么要运行相同的平台,但是程序的性能却有所不同。在我在终端上运行并在其上进行编辑之前,这看起来非常不错,但是在移植到Eclipse之后,它使我感到困惑。

最佳答案

您的第一条规则并不是很好。

您可以将其重命名为all,它将“起作用”。但是更好的方法是:

all: legrec

legrec: legrec.o game.o board.o piece.o
    $(CC) legrec.o game.o board.o piece.o -Wall -Werror -pedantic -o legrec

即规则名称应与产生的输出匹配。

如果在命令行上仅键入make,则会遇到第一个规则(这就是它对您有用的原因)。我猜您的IDE正在运行make all,而您 undefined 这样的规则。

关于c++ - 无法在Eclipse CDT中建立Makefile,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10633978/

10-17 01:42