用gcc编译的程序没有执行权限

风中之哨 2013-04-30 04:16:10
今天突然发现我在ubuntu中用gcc编译一个文件后,生成的可执行文件没有执行权限,就算chmod 777 后也无法执行!求教!
gcc -c pid.c -o pid
chmod a+x pid
./pid
结果:
bash: ./pid: cannot execute binary file
用file查看:
file pid
结果
pid: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped

下面是用file命令查看以前写的一个测试程序,这个是好的。这个以前也是用同样的gcc命令编译的,而且编译的结果本身就有可执行权限。但是用file命令发现和上面的不样
file str-test
结果:
str-test: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x86469a8dac9963f16a4986ceec9fbf1f8f689372, not stripped


求解,谢谢
...全文
887 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
风中之哨 2013-04-30
  • 打赏
  • 举报
回复
我暴汗!好久没有用gcc了。。。我今天竟然犯了这样的低级错误,而且还为此折腾了一个下午!真是万分惭愧啊。。。 感谢lishanchao ! 感谢prohibit !
引用 1 楼 lishanchao 的回复:
楼主用了-c选项,-c选项的含义: -c Compile or assemble the source files, but do not link. 所以,-o选项输出的pid,实际是一个.o文件,有关键字“relocatable”。 楼主用gcc pid.c -o pid生成的才是可执行文件,“executable”。
prohibit 2013-04-30
  • 打赏
  • 举报
回复
是的,gcc pid.c -o pid
沭水河畔 2013-04-30
  • 打赏
  • 举报
回复
楼主用了-c选项,-c选项的含义: -c Compile or assemble the source files, but do not link. 所以,-o选项输出的pid,实际是一个.o文件,有关键字“relocatable”。 楼主用gcc pid.c -o pid生成的才是可执行文件,“executable”。

23,125

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧