未定义的函数引用 w/ header

Undefined reference to function when included w/ header

我对为什么会出现这个特定错误感到困惑。 被调用的函数看起来一样,所以我认为这不是 type/case-sensitive 错误。我已经包含了我的 makefile、有问题的 header 以及使用 header + 调用函数的 C 文件的代码片段。

如果还有什么相关的,我可以提供。 感谢所有提供帮助的人!

game_state.h

#ifndef GAME_STATE_H
#define GAME_STATE_H

typedef struct Game_Condition_struct {
    bool vertical_win;
    bool down_diag_win;
    bool up_diag_win;
    char* player_char;
} GAME;

void Game_Over(BOARD* board);
void Win_Check(BOARD* board, GAME* game_condition);

#endif

moves.c 片段

#include "game_state.h"
... // other code above
else {
        Make_Move(board, user_move, player_char);
        Print_Board(board);
        // IF-ELSE to change the player turn
        if (*player_char == 'X') {
            *player_char = 'O';
        }
        else {
            *player_char = 'X';
        }
        Game_Over(board);
}

game_state.c

void Game_Over(BOARD* board) {
     GAME game_condition;
     Win_Check(board, &game_condition);
}

生成文件

connectn.out: board.o main.o read_args.o moves.o game_state.o
     gcc -g -Wall -o connectn.out board.o main.o read_args.o moves.o

main.o: board.h read_args.h moves.h game_state.h main.c
     gcc -g -Wall -c -o main.o  main.c

board.o: board.h board.c
     gcc -g -Wall -c -o board.o board.c

read_args.o: read_args.h read_args.c
     gcc -g -Wall -c -o read_args.o read_args.c

moves.o: moves.h board.h game_state.h moves.c
     gcc -g -Wall -c -o moves.o moves.c

game_state.o: game_state.h board.h game_state.c
     gcc -g -Wall -c -o game_state.o game_state.c

clean:
     rm *.o *.out

如果我不包含 Game_Over(board) 调用,代码将按预期工作,所以我很困惑为什么没有定义它。 BOARD是我做的一个struct,类似GAME。

您没有 link game_state.o 进入 connectn.out。在 Makefile 的第 2 行末尾添加 game_state.o