Difference between -shared and -Wl,-shared of the GCC options

烈酒焚心 提交于 2019-11-29 02:47:46

问题


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

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.

Thanks.


回答1:


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.

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

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.




回答2:


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.



来源:https://stackoverflow.com/questions/4623915/difference-between-shared-and-wl-shared-of-the-gcc-options

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!