gpt4 book ai didi

C、架构 x86_64 的 undefined symbol

转载 作者:行者123 更新时间:2023-11-30 16:26:40 25 4
gpt4 key购买 nike

我正在为我的 CS 类(class)编写一个 tic-tac-toe 程序,当我进行编译时,我不断收到此错误。

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”类型时,错误消息就会消失,但并非所有函数声明都是 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

关于C、架构 x86_64 的 undefined symbol ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52979816/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com