我的代码
#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/