简体   繁体   English

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

[英]C, Undefined symbols for architecture x86_64

I am writing a tic-tac-toe program for my CS class and I keep on getting this error when I go to compile. 我正在为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)

Whenever I make all of my function declarations of the type 'void' the error message goes away, but not all of them are void so I can't do this. 每当我将所有函数声明都设置为“ void”类型时,错误消息就会消失,但是并非所有声明都是无效的,所以我不能这样做。 Here is what I have written so far. 这是我到目前为止所写的。

#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};
        }
    }
}

I'm using VScode on Mac, coding in c, I'm compiling with 'gcc tictactoe.c -o tictactoe' 我在Mac上使用VScode,在c中进行编码,正在使用'gcc tictactoe.c -o tictactoe'进行编译

Make sure your definitions (implementations) have the same signature as the declarations. 确保您的定义(实现)具有与声明相同的签名。 Then make sure you list all .c or .o files (depending on whether you compile the objects separately) in the final gcc command. 然后,确保在最终的gcc命令中列出所有.c .o文件(取决于是否分别编译对象)。

So if you compiled to objects, use: 因此,如果您编译为对象,请使用:

gcc -o tictactoe tictactoe.c *.o

Or if your functions are just in other source files, 或者,如果您的功能仅在其他源文件中,

gcc -o tictactoe *.c

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM