GCC选项的-shared和-Wl -shared之间的差异

时间:2022-06-20 02:23:09

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

我知道-Wl -shared是ld的一个选项。

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

And some person like this

还有像这样的人

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

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

我想知道-shared和-Wl -shared之间有没有什么区别。

Thanks.

谢谢。

2 个解决方案

#1


13  

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.

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

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

要获得更多信息,grep用于在GCC /config/目录和子目录*享。

Edit: 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.

编辑:给出一个具体的例子:在i386 FreeBSD中,gcc -shared将会链接到对象文件中。o,虽然没有共享,它将在crtend中链接。o。因此,共享和-Wl共享是不等效的。

#2


0  

I don't think there is any difference. -shared is not a supported option of gcc and it is passed to linker whether you specify it with -Wl or not. -Wl option of gcc is used to specify that a comma separated list of options is to be passed to linker for further processing.

我不认为有什么不同。-shared不是gcc支持的选项,不管你是否用-Wl指定它,它都会传递给链接器。gcc的-Wl选项用于指定将一个逗号分隔的选项列表传递给链接器以进行进一步处理。

#1


13  

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.

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

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

要获得更多信息,grep用于在GCC /config/目录和子目录*享。

Edit: 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.

编辑:给出一个具体的例子:在i386 FreeBSD中,gcc -shared将会链接到对象文件中。o,虽然没有共享,它将在crtend中链接。o。因此,共享和-Wl共享是不等效的。

#2


0  

I don't think there is any difference. -shared is not a supported option of gcc and it is passed to linker whether you specify it with -Wl or not. -Wl option of gcc is used to specify that a comma separated list of options is to be passed to linker for further processing.

我不认为有什么不同。-shared不是gcc支持的选项,不管你是否用-Wl指定它,它都会传递给链接器。gcc的-Wl选项用于指定将一个逗号分隔的选项列表传递给链接器以进行进一步处理。