gpt4 book ai didi

c - 错误 : file was built for unsupported file format which is not the architecture being linked (x86_64)

转载 作者:太空宇宙 更新时间:2023-11-04 02:03:33 31 4
gpt4 key购买 nike

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

这是我的代码:

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

如果有人能告诉我发生了什么事以及如何解决这个错误,那就太好了。谢谢。

最佳答案

您正试图将程序的输入文件传递给 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

关于c - 错误 : file was built for unsupported file format which is not the architecture being linked (x86_64),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23536696/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com