C,体系结构x86_64的未定义符号

问题描述 投票:0回答:1

我正在为我的CS类编写一个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”类型的所有函数声明时,错误消息就会消失,但并非所有这些都是无效的,所以我不能这样做。这是我到目前为止所写的内容。

#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'进行编译

c
1个回答
0
投票

确保您的定义(实现)与声明具有相同的签名。然后确保在最终的gcc命令中列出所有.c或.o文件(取决于您是否单独编译对象)。

因此,如果您编译为对象,请使用:

gcc -o tictactoe tictactoe.c *.o

或者,如果您的函数只是在其他源文件中,

gcc -o tictactoe *.c
© www.soinside.com 2019 - 2024. All rights reserved.