user3612441
user3612441

Reputation: 21

Error: file was built for unsupported file format which is not the architecture being linked (x86_64)

Hi i know there are many questions regarding this question but i can't seem to understand any of them. i just have a simple code that reads a text file and prints it to screen (just to check if it does what i want it to do). and then closes the stream.

this is my code:

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();
}

running it with

gcc Player.c ThreesInput.txt

i get this error:

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

if anyone could tell me whats happened and how to fix this error would be great. Thanks.

Upvotes: 1

Views: 3681

Answers (1)

Paul R
Paul R

Reputation: 213130

You're trying to pass your program's input file to gcc, which is confusing for the compiler/linker. You need to first compile your program source code into an executable, and then run the executable with your input file:

$ 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

Upvotes: 3

Related Questions