GCC创建一个共享对象而不是可执行二进制文件 [英] GCC creates a shared object instead of an executable binary

查看:219
本文介绍了GCC创建一个共享对象而不是可执行二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我正在建造的图书馆。当我运行以下任何一个对象时,所有对象都会依次编译和链接:
ar rcs lib / libryftts.a $ ^



gcc -shared $ ^ -o lib / libryftts.so



在我的Makefile中。我也能够成功地将它们安装到 / usr / local / lib
当我使用nm测试文件时,所有函数都在那里。
我的问题是,当我运行 gcc testing / test.c -lryftts -o test&&文件./test gcc testing / test.c lib / libryftts.a -o test&&文件./test
它说:



test:ELF 64位LSB共享对象 code>而不是 test:ELF 64位LSB可执行文件,如我所料。我做错了什么?

解决方案


我做错了什么?


无。



听起来像您的GCC被配置为构建 - 馅饼默认情况下为二进制文件。这些二进制文件实际上是共享库(类型为 ET_DYN ),除非它们像普通可执行文件那样运行。



所以你应该运行你的二进制文件,(如果它有效的话)不用担心它。



或者你可以将你的二进制文件与 gcc -no-pie ... 并且应该产生一个非< PIE 类型的可执行文件 ET_EXEC ,其中文件会说 ELF 64位LSB可执行文件


I have a library I am building. All of my objects compile and link successively when I run either one of: ar rcs lib/libryftts.a $^

gcc -shared $^ -o lib/libryftts.so

in my Makefile. I also am able to successfully install them into /usr/local/lib When I test the file with nm, all the functions are there. My problem is that when I run gcc testing/test.c -lryftts -o test && file ./test or gcc testing/test.c lib/libryftts.a -o test && file ./test it says:

test: ELF 64-bit LSB shared object instead of test: ELF 64-bit LSB executable as I would expect. What am I doing wrong?

解决方案

What am I doing wrong?

Nothing.

It sounds like your GCC is configured to build -pie binaries by default. These binaries really are shared libraries (of type ET_DYN), except they run just like a normal executable would.

So your should just run your binary, and (if it works) not worry about it.

Or you could link your binary with gcc -no-pie ... and that should produce a non-PIE executable of type ET_EXEC, for which file will say ELF 64-bit LSB executable.

这篇关于GCC创建一个共享对象而不是可执行二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆