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

后端 未结 2 1096
遇见更好的自我
遇见更好的自我 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条回答
  •  猫巷女王i
    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.

提交回复
热议问题