错误:文件是为不受支持的文件格式构建的,而不是链接的体系结构(x86_64)

时间:2014-05-08 08:34:56

标签: c macos gcc terminal

嗨,我知道有很多关于这个问题的问题,但我似乎无法理解其中任何一个问题。我只是有一个简单的代码,它读取文本文件并将其打印到屏幕上(只是为了检查它是否符合我的要求)。然后关闭流。

这是我的代码:

int table[4][4];
static char INFILE[BUFSIZ];

int j = 0;
static void trim_line(char linecharacter[])
{
    int i = 0;
    int linenumber = 1;

    //  LOOP UNTIL WE REACH THE END OF line
    while(linecharacter[i] != '\0')
    {

        //  CHECK FOR CARRIAGE-RETURN OR NEWLINE
        if( (linecharacter[i] == '\r' || linecharacter[i] == '\n') && linenumber < 3 )
        {
            linenumber++; //increment the line number
            linecharacter[i] = '\0'; // overwrite with nul-byte
            break;          // leave the loop early
        }

        if( linenumber >= 3 && linenumber <=6 )
        {
             table[j][i] = linecharacter[i]; // insert int into array
                 printf("%c", linecharacter[i]); // check lines //error checking statement 
             i = i+1;            // iterate through character array
        }

        if( linenumber > 6)
        {
        // yet to be written
        }
    }
        printf("_\n");
}

void readinfile()
{
    FILE    *infile = fopen(INFILE, "r");
    // ENSURE THAT OPENING FILE HAS BEEN SUCCESSFUL
    if(infile == NULL) {
        printf("cannot open infile '%s'\n", INFILE);
        exit(EXIT_FAILURE);
    }
    // team != NULL
    char linecharacter[BUFSIZ];
    while( fgets(linecharacter, sizeof linecharacter, infile) !=NULL)
    {
        trim_line(linecharacter);
        j++;
    }
    //ENSURE THAT WE ONLY CLOSE FILES THAT ARE OPEN
    if(infile != NULL)
    {
        fclose(infile);
    }

}

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        printf("Failure to enter required arguments %d \n", argc);
        exit(EXIT_FAILURE);
    }
    strcpy(INFILE, argv[1]);
    readinfile();
}

运行它
gcc Player.c ThreesInput.txt

我收到此错误:

ld: warning: ignoring file ThreesInput.txt, file was built for unsupported file format ( 0x33 0x30 0x30 0x20 0x70 0x69 0x65 0x63 0x65 0x73 0x3B 0x20 0x31 0x32 0x30 0x2E ) which is not the architecture being linked (x86_64): ThreesInput.txt

如果有人能告诉我发生了什么,如何解决这个错误会很棒。感谢。

1 个答案:

答案 0 :(得分:3)

您正在尝试将程序的输入文件传递给gcc,这对编译器/链接器来说很困惑。您需要先将程序源代码编译为可执行文件,然后使用输入文件运行可执行文件:

$ gcc -Wall Player.c           # compile Player.c source code to a.out executable
$ ./a.out ThreesInput.txt      # run a.out executable with input file ThreesInput.txt