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.
There is a difference between passing
-sharedto gcc or-sharedto ld (via-Wl). Passing-sharedto GCC may enable or disable other flags at link time. In particular, differentcrt*files might be involved.To get more information, grep for
-sharedin GCC’sgcc/config/directory and subdirectories.Edit: To give a specific example: on i386 FreeBSD,
gcc -sharedwill link in object filecrtendS.o, while without-shared, it will link incrtend.oinstead. Thus,-sharedand-Wl,-sharedare not equivalent.