红联Linux门户
Linux帮助

linux下可执行文件cannot execute binary file

发布时间:2016-05-23 09:47:34来源:linux网站作者:jahentao

初次尝试:

代码如下

bash: ./file: Permission denied//权限不够

于是我干脆就

chmod 777 file

可是运行

bash: cannot execute binary file


找了相关的Linux 下可执行文件不能运行cannot execute binary file:
我在Linux下写程序,编译通过,但是运行时每次提示:

bash: ./Test: Permission denied

然后我就给权限:

root@ubuntu :~/source/ThreadPool# chmod +x Test

然后运行:

root@ubuntu :~/source/ThreadPool# ./Test
bash: ./Test: cannot execute binary file

Test.cpp是我写的测试程序,其实很简单,就一句话:

include <stdio.h>

int  main()
{
printf("hello, world");
return 0;
};

但就是程序不能运行。很诡异。我其他程序也不能运行。


原来是因为,我使用gcc使用的命令是

gcc -c file1.c -o file

-c 好像是只编译,不链接。

-c 只编译并生成目标文件。

不加 -c 就应该可以了。


本文永久更新地址:http://www.linuxdiyf.com/linux/20868.html