c - 读取二进制文件,无法执行二进制文件: Exec format error

标签 c linux binary

我的代码

#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("%e\n", 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

关于c - 读取二进制文件,无法执行二进制文件: Exec format error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35089419/

相关文章:

linux bash 'sort' 按字典顺序

mysql - 子查询不适用于 Windows,但适用于 Linux

java - GZipInputStream .read() 将零插入缓冲区

c - 如何阻止文件名/路径出现在已编译的 C 二进制文件中

写入文件成功时的回调,C

C 随机数生成器 - 它的变化如此缓慢。该怎么办?

c - C 中 do-while-false 的用例?

linux - 如何在 rpm 中更改 "Build Host"

java - 将 Long 转换为 DateTime 从 C# 日期到 Java 日期

c - 如何使用 MPI 传递带有动态数组的自定义结构?