GCC 选项的 -shared 和 -Wl,-shared 之间的区别 [英] Difference between -shared and -Wl,-shared of the GCC options

查看:23
本文介绍了GCC 选项的 -shared 和 -Wl,-shared 之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 -Wl,-sharedld 的一个选项.我见过有人这样编译,

I know -Wl,-shared is a option of ld. I've seen some person compile like this,

$ gcc -shared -Wl,-soname,libtest.so -o libtest.so *.o

还有这样的人

$ gcc -Wl,-shared -Wl,-soname,libtest.so -o libtest.so *.o

所以,我想知道 -shared-Wl,-shared 之间是否有一些区别.

So, I want to know if there is some difference between -shared and -Wl,-shared.

谢谢.

推荐答案

传递 -shared 到 gcc 或 -shared 到 ld(通过 -Wl).将 -shared 传递给 GCC 可能会在链接时启用或禁用其他标志.特别是,可能涉及不同的 crt* 文件.

There is a difference between passing -shared to gcc or -shared to ld (via -Wl). Passing -shared to GCC may enable or disable other flags at link time. In particular, different crt* files might be involved.

要获取更多信息,请在 GCC 的 gcc/config/ 目录和子目录中查找 -shared.

To get more information, grep for -shared in GCC's gcc/config/ directory and subdirectories.

举一个具体的例子:在 i386 FreeBSD 上,gcc -shared 将链接到目标文件 crtendS.o,而没有-shared,它将改为链接在 crtend.o 中.因此,-shared-Wl,-shared 不是等价的.

To give a specific example: on i386 FreeBSD, gcc -shared will link in object file crtendS.o, while without -shared, it will link in crtend.o instead. Thus, -shared and -Wl,-shared are not equivalent.

这篇关于GCC 选项的 -shared 和 -Wl,-shared 之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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