Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 428
Yantao Xie Avatar asked Jan 07 '11 08:01

Yantao Xie


1 Answers

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.

like image 114
F'x Avatar answered Sep 28 '22 08:09

F'x