2015-09-19 42 views
1

謝謝你的一切幫助。我已經聯繫了我的講師,並正在與他一起尋求解決方案。再次感謝你。製作連接4遊戲C

對於一個小項目,我們需要連接四個遊戲。我們的項目分爲幾個部分,每個星期我們都會分配一個不同的部分來開展工作。

這個星期我們必須補足這個專欄的工作,我的意思是我們必須使用一個名爲get_column的函數,並且用它從用戶那裏讀取下一段作品的有效列號。

所以我們提供的以下文件connect4.h(用於存儲功能的文件),(忽略它只是SEM的當前周的名稱),week8.c這是我目前編輯的文件。

到目前爲止,我有以下的,但是當我去檢查程序工作,到目前爲止,我得到的編譯錯誤說:

"ld: warning: ignoring file week8_object.o, file was built for unsupported file format (0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00) which is not the architecture being linked (x86_64): week8_object.o Undefined symbols for architecture x86_64: "_main", referenced from: implicit entry/start for main executable ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)"

我使用編譯的代碼是:gcc week8.c week8_object.o

我的代碼:

#include <stdio.h> 
#include "connect4.h" 

/* get_move 
Prompts the user to enter a column, then checks that 
- the column is in the valid range (1-COLS) 
- that the column is not full (use function column_full to check) 
If an invalid column is entered, the user is reprompted until it is valid 
Returns the column number between 1 and COLS 
*/ 

int get_move (int board[COLS][ROWS]){ 

    int col; 

    printf("Please enter a column number:"); 
    scanf("%d",&col); 

    if(col<0 && col<=COLS){ 
     printf("Your token has been placed"); 
    } 
    else{ 
     printf("Your token has not been placed"); 
    } 
    return(0); 
} 

頭文件

#ifndef CONNECT4_H 
#define CONNEXT4_H 1 

#define ROWS 6 
#define COLS 7 

// displays the board to the screen 
int display_board (int[COLS][ROWS]) ; 

// sets up the board to an empty state 
int setup_board (int[COLS][ROWS]) ; 

// Returns TRUE if the specified column in the board is completely full 
// FALSE otherwise 
// col should be between 1 and COLS 
int column_full (int[COLS][ROWS], int col) ; 

// prompts the user to enter a move, and checks that it is valid 
// for the supplied board and board size 
// Returns the column that the user has entered, once it is valid (1-COLS) 
int get_move (int[COLS][ROWS]) ; 

// adds a token of the given value (1 or 2) to the board at the 
// given column (col between 1 and COLS inclusive) 
// Returns 0 if successful, -1 otherwise 
int add_move (int b[COLS][ROWS], int col, int colour) ; 

// determines who (if anybody) has won. Returns the player id of the 
// winner, otherwise 0 
int winner (int[COLS][ROWS]) ; 

// determines if the board is completely full or not 
int board_full (int[COLS][ROWS]) ; 


#endif 

我不知道如何添加目標文件代碼,因爲我不知道如何打開它。我的代碼到目前爲止只打印語句,如果用戶在這些限制內輸入的值。我還沒有添加任何內容來檢查列是否已滿,請不要誤認這一點。我只是逐步檢查。

+0

1.)添加編譯器命令行 - 2.)添加詳細信息您的預製對象文件應包含哪些代碼。可能只是一個損壞的文件,不能從* this *描述中辨別出來。 –

+0

所以我們被告知用來編譯的命令行(我使用mac和geany作爲我的程序來編輯):gcc week8.c week8_object.o。我不太確定你想要我做什麼,會上傳目標文件的幫助? – sandalwood

+0

相關:http://stackoverflow.com/questions/32448016/error-linking-object-files – melpomene

回答

0

根據快速谷歌搜索,這意味着你的目標文件是ELF格式,這基本上意味着它是爲Linux構建的。 Mac OS不使用ELF,因此您無法鏈接該文件。

的選項有:

  1. 切換到Linux的發展,或
  2. 獲取誰創造編譯的Mac版本的人。
+0

哦,這是一個痛苦...是不是一種類型的Linux?我希望在最好的情況下,在Windows中給它一個鏡頭。我的講師做了這個文件,當涉及到電子郵件聯繫時,他是非常不可靠的......我會讓你知道在Windows上的結果是什麼。謝謝。 – sandalwood

+0

@sandalwood Mac是一種unix(就像Linux一樣(或者更準確地說,Linux是「類似unix」的)),但是二進制文件通常在不同的unix變體之間是不可移植的。但是,如果您可以獲得源代碼('week8_object.c'),那麼在Linux和Mac上都有很好的工作機會。 – melpomene

+0

哦,對不起,如果我出來懶惰沒有谷歌搜索。我只是不確定將搜索主題放在什麼位置上,因爲錯誤本身讓我感到困惑。 – sandalwood