[英]C, Undefined symbols for architecture x86_64
我正在為CS類編寫井字游戲程序,並且在繼續編譯時不斷出現此錯誤。
Undefined symbols for architecture x86_64:
"_check_end_of_game", referenced from:
_main in tictactoe-03b26b.o
"_generate_player2_move", referenced from:
_main in tictactoe-03b26b.o
"_get_player1_move", referenced from:
_main in tictactoe-03b26b.o
"_print_winner", referenced from:
_main in tictactoe-03b26b.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
每當我將所有函數聲明都設置為“ void”類型時,錯誤消息就會消失,但是並非所有聲明都是無效的,所以我不能這樣做。 這是我到目前為止所寫的。
#include <stdio.h>
#include <stdbool.h>
#define SIZE 3
void clear_table(char board[SIZE][SIZE]); void display_table(char
board[SIZE][SIZE]);
void get_player1_move(char board[SIZE][SIZE], int row, int col);
void generate_player2_move(char board[SIZE][SIZE], int row, int col);
bool check_end_of_game(char board[SIZE][SIZE]); void print_winner(char
board[SIZE][SIZE]);
int main (){
char board[SIZE][SIZE];
int row, col;
clear_table(board); //Clears the table
display_table(board); //Display the table
do {
get_player1_move(board, row, col); //Have player 1 enter their move
generate_player2_move(board, row, col); //Generate player 2 move
} while(check_end_of_game(board) == false); //Do this while the game hasn't ended
print_winner(board); //after game is over, print who won
return 0;
}
void display_table(char board[SIZE][SIZE]) {
int i;
printf("The current state of the game is: \n");
for (i = 0; i <= SIZE; i++){
for(i = 0; i <= SIZE; i++){
printf("%c ", board[i][i]);
}
}
}
void clear_table(char board[][SIZE]) {
int i;
for (i = 0; i <= SIZE; i++) {
for (i = 0; i <= SIZE; i++) {
int board[SIZE][SIZE] = {0};
}
}
}
我在Mac上使用VScode,在c中進行編碼,正在使用'gcc tictactoe.c -o tictactoe'進行編譯
確保您的定義(實現)具有與聲明相同的簽名。 然后,確保在最終的gcc命令中列出所有.c 或 .o文件(取決於是否分別編譯對象)。
因此,如果您編譯為對象,請使用:
gcc -o tictactoe tictactoe.c *.o
或者,如果您的功能僅在其他源文件中,
gcc -o tictactoe *.c
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.