1

エラーが発生し続けます

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

端末で実行したので、makefile は完全に機能すると確信しています。しかし、空の Makefile プロジェクトを作成してすべてを eclispe にインポートしようとすると、プログラムをコンパイルできませんでした。だから私は日食の設定で何かを逃したのですか?

とにかく、これは私のメイクファイルです。見て、私を修正してください。ありがとう

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 に移植した後は、奇妙なエラーに悩まされます。

4

3 に答える 3

1

あなたの最初のルールはあまり良くありません。

に名前を変更すると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されていると思いますが、そのようなルールを定義していません。

于 2012-05-17T10:30:57.197 に答える
0

私は専門家ではありませんが、お手伝いさせていただきます。maketargetの名前を変更し て、次の行を追加 progしてみてくださいlegrec"
.PHONY: all clean
all: legrec

Also your makefile doesn't have clean target. For that looking at your make file I suggest adding

clean:
    @rm *.o legrec
于 2012-05-17T10:37:45.257 に答える
0

重複を減らすために、さまざまな方法でメイクファイルを改善できます。

makecppファイルをオブジェクトファイルに変換する方法を知っているので、それを伝える必要はありません。使用するコンパイラとオプションを定義するだけです: CPPFLAGS を追加しました。

makemakefile で見つかった最初のターゲット (この場合は「legrec」) をビルドします。LD (リンク) コマンドの $@ は を参照しlegrecます。$^ は、前提条件 (つまり、オブジェクトのリスト) を参照します。

これが私のバージョンです:

CC = g++
CPPFLAGS = -Wall -Werror -pedantic
LDFLAGS =

legrec: legrec.o game.o board.o piece.o
    $(LD) $(LDFLAGS) $^ -o $@

legrec.o: game.h
game.o:   board.h piece.h move.h player.h game.h
board.o:  board.h piece.h move.h player.h
piece.o:  board.h piece.h move.h player.h

.PHONY: clean
clean:
    @rm -f *.o legrec

-g または -O などを CPPFLAGS 行に追加できることに注意してください。ところで、-Wall によって生成されるよりも多くの警告がコンパイラによって表示される可能性があります。Cの場合、私は通常次を使用します:

-Wall \
-Wextra \
-Wshadow \
-Wstrict-prototypes \
-Wmissing-prototypes \
-Wundef \
-Wunreachable-code \
-Wunused \
-Wcast-qual
于 2012-05-17T13:23:00.843 に答える