今天在cygwin下面使用gcc编译的时候,用了命令,而非makefile。 命令如下: gcc -o myapp -c hello.c 结果使用 ./myapp 运行时,提示: “cannot execute binary file” 。 开始我百思不得其解,通过ls查看文件权限,将其mode 改成 0777。 再次执行./myapp,依旧提示 “cannot execute binary file” 。 于是baidu, google, 最终找到了原因: The In fact, if you ran this without the For reference (and giggles), the man entry on the
(此段英语摘自: 也就是说带了-c编译时,-o生成的是.o文件,可以使用file 命令查看文件类型。 file ./myapp ./myapp: 80386 COFF executable not stripped - version 30821 而正常生成的执行程序的类型为 : ( cygwin 安装于windows操作系统下) ./my_app.exe: PE32 executable (console) Intel 80386 (stripped to external PDB), for MS Windows 更改了编译命令, gcc -o myapp hello.c ./myapp 一切正常。 总结: 如果你遇到了“cannot execute binary file” 这样的提示,还请确认下,你的gcc编译命令是否有问题, 生成的文件是否是你预期的执行文件。 |
|
来自: happy123god > 《读书笔记及小结》