C语言 读取二进制文件,无法执行二进制文件:执行格式错误



我的代码

#include <stdio.h>
#define FILENAME "m_6"
int main() {
   float f;
   FILE * file;
   // read values
   if ( ! (file = fopen(FILENAME,"r")))
      return 1;
   while ( fread( &f, sizeof(float), 1, file ))
      printf("%en", f);
   fclose( file );
}

当我使用 gcc gcc -c n1.c -o n1 编译时

并尝试运行它,我得到了

bash: ./n1: cannot execute binary file: Exec format error

文件 m_6 和 n1.c 在同一台计算机上执行。

3.13.0-76-generic #120-Ubuntu SMP Mon Jan 18 15:59:10 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

如何解决这个问题?

gcc -c编译源文件而不链接。

从命令取消-c

最新更新