为什么GCC根据文件创建共享对象而不是可执行二进制文件? [英] Why does GCC create a shared object instead of an executable binary according to file?

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

问题描述

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

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

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

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而不是我期望的test: ELF 64-bit LSB executable.我在做什么错了?

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?

没事.

听起来您的GCC已配置为默认构建-pie二进制文件.这些二进制文件实际上是 共享库(类型为ET_DYN),只是它们的运行方式与普通可执行文件相同.

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.

或者您可以将二进制文件与gcc -no-pie ...链接,这将产生类型为ET_EXEC的非PIE可执行文件,为此file将表示ELF 64-bit LSB executable.

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天全站免登陆