繁体   English   中英

体系结构x86_64的未定义符号:C ++项目

[英]Undefined symbols for architecture x86_64: C++ Project

我正在编写一个我想将其转换为汇编代码的c ++项目。 尽管我研究了此特定错误,但给出的答案似乎都无法解决我的问题。 这是代码:

    //
    //  main.cpp
    //  TicTacToe
    //
    //
//

#include <iostream>

void printboard(char board[][3]);
void update(char board[][3],char,int,int);
bool isValid(char board[][3],char,int,int);
int menu();
void game1(char board[][3]);
void game2(char board[][3]);
void game3(char board[][3]);
void game4(char board[][3]);
void def();
bool state(char board[][3],int,int);

using namespace std;


int main(int argc, const char * argv[]) {
    //game board, initialize with 0's
    char board[3][3] = {{'0','0','0'},{'0','0','0'},{'0','0','0'}};
    int choice = menu();
    switch(choice)
    {
        case 1: game1(board);break;
        case 2: game2(board);break;
        case 3: game3(board);break;
        case 4: game4(board);break;
        default: def();break;
    }
    return 0;
}

int menu()
{
    int temp;
    cout<<"Welcome to Tic-Tac-Toe. Please enter a mode in which to play.\n";
    cout<<"Enter 1 to choose to play against another opponent.\n";
    cout<<"Enter 2 to play against easy AI.\n";
    cout<<"Press 3 to play against medium AI.\n";
    cout<<"Press 4 to play against hard AI.\n";
    cin>>temp;
    return temp;
}



void update(char board[][3],char choice,int i,int j)
{
    toupper(choice);
    if(choice == 'O'){
        board[i][j] = 'O';
    }else{
        board[i][j] = 'X';
    }
}

void printboard(char board[][3])
{
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cout<<board[i][j]<<"|";
        }
        cout<<endl;
        cout<<"______"<<endl;
    }
}

void def()
{
    cout<<"Invalid choice. Enter numbers 1-4.\n";
}

bool isValid(int board[3][3],char choice,int row,int col)
{
    toupper(choice);
    if(row >= 3 || col >=3)
        return false;
    if(choice != 'O' || choice != 'X')
        return false;
    if(board[row][col] == 'O' || board[row][col] == 'X')
        return false;
    return true;
}

bool state(char board[][3],int choice1,int choice2)
{
    //check for win state, these are absolutes
    if((board[0][2] == choice1 && board[1][1] == choice1 && board[0][2] == choice1))
    {
        cout<<"Player 1 wins!!!\n";
        return false;
    }
    else if(board[0][2] == choice2 && board[1][1] == choice2 && board[0][2] == choice2){
        cout<<"Player 2 wins!!!\n";
        return false;
    }
    if(board[0][0] == choice1 && board[1][1] == choice1 && board[2][2] == choice1){
        cout<<"Player 1 wins!!!\n";
        return false;
    }
    else if(board[0][0] == choice2 && board[1][1] == choice2 && board[2][2] == choice2){
        cout<<"Player 2 wins!!!\n";
        return false;
    }
    if(board[0][0] == choice1 && board[1][0] == choice1 && board[2][0] == choice1){
        cout<<"Player 1 wins!!!\n";
        return false;
    }
    else if(board[0][0] == choice2 && board[1][0] == choice2 && board[2][0] == choice2){
        cout<<"Player 2 wins!!!\n";
        return false;
    }
    if(board[0][0] == choice1 && board[0][1] == choice1 && board[0][2] == choice1){
        cout<<"Player 1 wins!!!\n";
        return false;
    }
    else if(board[0][0] == choice2 && board[0][1] == choice2 && board[0][2] == choice2){
        cout<<"Player 2 wins!!!\n";
        return false;
    }
    if(board[0][2] == choice1 && board[1][2] == choice1 && board[2][2] == choice1){
        cout<<"Player 1 wins!!!\n";
        return false;
    }
    else if(board[0][2] == choice2 && board[1][2] == choice2 && board[2][2] == choice2){
        cout<<"Player 2 wins!!!\n";
        return false;
    }
    if(board[1][0] == choice1 && board[1][1] == choice1 && board[1][2] == choice1){
        cout<<"Player 1 wins!!!\n";
        return false;
    }
    else if(board[1][0] == choice2 && board[1][1] == choice2 && board[1][2] == choice2){
        cout<<"Player 2 wins!!!\n";
        return false;
    }
    if(board[2][0] == choice1 && board[2][1] == choice1 && board[2][2] == choice1){
        cout<<"Player 1 wins!!!\n";
        return false;
    }
    else if(board[2][0] == choice2 && board[2][1] == choice2 && board[2][2] == choice2){
        cout<<"Player 2 wins!!!\n";
        return false;
    }

    return true;
}




void game1(char board[][3])
{

    char choice1;
    char choice2;
    int row;
    int col;
    bool gamestate;
    bool valid;
    cout<<"Player 1, would you like to be X or O?\n";
    cin>>choice1;
    cout<<"Player 2, would you like to be X or O?\n";
    cin>>choice2;

    do{
        do{
            //Get players intput and check if the input is valid
            cout<<"Player 1, enter row/col to place your move.\n";
            cin>>row>>col;
            valid = isValid(board,choice1,row,col);
            cout<<"Player 2, enter row/col to place your move.\n";
            cin>>row>>col;
            valid = isValid(board,choice2,row,col);
        }while(valid);
        //check the state of the game
        gamestate = state(board,choice1,choice2);
    }while(gamestate);

}

void game2(char board[][3])
{
    cout<<"In game 2"<<endl;
}

void game3(char board[][3])
{
    cout<<"In game 3"<<endl;
}

void game4(char board[][3])
{
    cout<<"In game 4"<<endl;
}

这是Xcode输出的错误。 它指出问题出在函数IsValid。 虽然我似乎在传递数组,并且原型定义正确。 我不知道这是怎么回事。

Ld /Users/justinfulkerson/Library/Developer/Xcode/DerivedData/TicTacToe-fioiynyiwrhpecfdznfogllqdmvx/Build/Products/Debug/TicTacToe normal x86_64
    cd /Users/justinfulkerson/dev/CSC11/FulkersonJustinCSC11/Project/TicTacToe
    export MACOSX_DEPLOYMENT_TARGET=10.10
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -L/Users/justinfulkerson/Library/Developer/Xcode/DerivedData/TicTacToe-fioiynyiwrhpecfdznfogllqdmvx/Build/Products/Debug -F/Users/justinfulkerson/Library/Developer/Xcode/DerivedData/TicTacToe-fioiynyiwrhpecfdznfogllqdmvx/Build/Products/Debug -filelist /Users/justinfulkerson/Library/Developer/Xcode/DerivedData/TicTacToe-fioiynyiwrhpecfdznfogllqdmvx/Build/Intermediates/TicTacToe.build/Debug/TicTacToe.build/Objects-normal/x86_64/TicTacToe.LinkFileList -mmacosx-version-min=10.10 -stdlib=libc++ -Xlinker -dependency_info -Xlinker /Users/justinfulkerson/Library/Developer/Xcode/DerivedData/TicTacToe-fioiynyiwrhpecfdznfogllqdmvx/Build/Intermediates/TicTacToe.build/Debug/TicTacToe.build/Objects-normal/x86_64/TicTacToe_dependency_info.dat -o /Users/justinfulkerson/Library/Developer/Xcode/DerivedData/TicTacToe-fioiynyiwrhpecfdznfogllqdmvx/Build/Products/Debug/TicTacToe

Undefined symbols for architecture x86_64:
  "isValid(char (*) [3], char, int, int)", referenced from:
      game1(char (*) [3]) in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

这是问题所在。 由于我的构建系统,我不得不修复两个编译器警告[这是其他错误]。 无论如何,这是一个显示问题/修复的差异:

--- gameasm.txt 2015-11-07 13:53:39.299520352 -0800
+++ gameasm.cpp 2015-11-07 14:30:50.049802299 -0800
@@ -52,7 +52,7 @@

 void update(char board[][3],char choice,int i,int j)
 {
-    toupper(choice);
+    choice = toupper(choice);
     if(choice == 'O'){
         board[i][j] = 'O';
     }else{
@@ -76,9 +76,9 @@
     cout<<"Invalid choice. Enter numbers 1-4.\n";
 }

-bool isValid(int board[3][3],char choice,int row,int col)
+bool isValid(char board[3][3],char choice,int row,int col)
 {
-    toupper(choice);
+    choice = toupper(choice);
     if(row >= 3 || col >=3)
         return false;
     if(choice != 'O' || choice != 'X')

暂无
暂无

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

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