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

后端 未结 2 1090
遇见更好的自我
遇见更好的自我 2020-12-29 10:43

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         


        
相关标签:
2条回答
  • 2020-12-29 11:20

    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.

    0 讨论(0)
  • 2020-12-29 11:25

    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.

    0 讨论(0)
提交回复
热议问题