C 包含标题时对函数的未定义引用
我一直不明白为什么会出现这个特定的错误。 被调用的函数看起来是一样的,所以我不认为它是一个类型/大小写敏感的错误。我已经包含了我的makefile、讨论中的头文件,以及使用头文件+调用函数的C文件的代码段 如果还有其他相关信息,我可以提供。 感谢所有帮助你的人 游戏状态C 包含标题时对函数的未定义引用,c,makefile,C,Makefile,我一直不明白为什么会出现这个特定的错误。 被调用的函数看起来是一样的,所以我不认为它是一个类型/大小写敏感的错误。我已经包含了我的makefile、讨论中的头文件,以及使用头文件+调用函数的C文件的代码段 如果还有其他相关信息,我可以提供。 感谢所有帮助你的人 游戏状态 #ifndef GAME_STATE_H #define GAME_STATE_H typedef struct Game_Condition_struct { bool vertical_win; bool
#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
移动.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);
}
游戏状态
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是我制作的一个结构,类似于GAME。您没有将
GAME\u state.o
链接到connectn.out
。将game\u state.o
添加到Makefile第二行的末尾。在moves.o之后,我将其放在末尾,这不是链接吗?真的很好奇你的意思!哦,我明白你现在的意思了,在实际的编译命令中;让我试试,我知道这很简单,非常感谢!要清楚的是,这就是它缺少的link命令。编译将源文件转换为目标文件(.o
)。链接将目标文件转换为程序(connectn.out
)(或共享库,但您没有构建其中的一个)。在游戏条件结构中,我想知道为什么没有横向赢项。我忘记了特定的赢项条件,但现在有一个:)