这个问题比较怪
开始编译的时候如下
[root@localhost first_drv_1]# ls
first_drv.c first_drv.mod.c first_drv.o Makefile Module.symvers
first_drv.ko first_drv.mod.o firstdrvtest.c modules.order
[root@localhost first_drv_1]# arm-linux-gcc -o firstdrv firstdrvtest.c
[root@localhost first_drv_1]# ls
firstdrv first_drv.ko first_drv.mod.o firstdrvtest.c modules.order
first_drv.c first_drv.mod.c first_drv.o Makefile Module.symvers
[root@localhost first_drv_1]# ./firstdrvtest
-bash: ./firstdrvtest: cannot execute binary file
google之发现解决方法
出现这个问题有如下原因:
1.文件的所有者和所有者所在组没有权限操作这个文件。
可以用chown命令修改该文件的所有者和所有组,具体用法如下:
chown -R root:root filename,-R表示循环递归的将目录下的所有文件都修改其所有者和所在组,前一个root所用户名,后一个root表示组。
2.32bits和64bits:系统都有所需的软件类型,64位和32位,如果64位用到了32位上就会出现这个问题。解决办法,下载可用版本。
来源http://blog.csdn.net/centre10/article/details/6023959但是方法一改了组和用户无效,我在fedora下编译然后运行,不存在2所说的问题
遂继续google之
在博文<Linux使用open出现Permission denied!>中我说道了这样的一种情况,造成这个问题的原因在于执行的文件本身出现了问题。
如我在<Linux使用open出现Permission denied!>中执行manageGlobalvar一样,使用file命令我们就可以发现问题:
可以发现问题所在了吧,我编译生成的文件不是一个可执行的文件,原因在于自己使用的编译方法出现了问题。
我使用的是:
而正确的用法是:
对这个编译的文件使用file命令查看:
因此要解决cannot execute binary file的问题在于重新按照正确的编译方法进行编译吧!
原文http://www.ecoviews.cn/net/archives/144.html
受此文提示[root@localhost first_drv_1]# ls
first_drv.c first_drv.mod.c first_drv.o Makefile Module.symvers
first_drv.ko first_drv.mod.o firstdrvtest.c modules.order
[root@localhost first_drv_1]# gcc -o firstdrv firstdrvtest.c
[root@localhost first_drv_1]# ls
firstdrv first_drv.ko first_drv.mod.o firstdrvtest.c modules.order
first_drv.c first_drv.mod.c first_drv.o Makefile Module.symvers
[root@localhost first_drv_1]# ./firstdrv
can't open!
Usage :
./firstdrv <on|off>
成功,暂时还没细研究arm-linux-gcc 和gcc为什么出来不一样
ps
arm-linux-gcc 是编译到 arm CPU 架构的 gcc 直接 gcc 命令,是编译到当前 CPU 架构的 gcc
所以开发板上运行还是得用arm-linux-gcc,这也是为什么arm-linux-gcc编译的不能在fedora上运行的原因了