Gcc -fPIC vs. -shared

When compiling a shared library with gcc / g ++, why -fPICnot the option -shared? Or, in another way, is there an option -fPICneeded for link time?

In short, I have to write:

gcc -c -fPIC foo.c -o foo.o
gcc -shared -fPIC foo.o -o libfoo.so  // with -fPIC

or enough:

gcc -c -fPIC foo.c -o foo.o
gcc -shared foo.o -o libfoo.so // without -fPIC
+4
source share
1 answer

, , , , , . -fPIC , GCC . , -shared, GCC . .

, . , , . . , , , .

, , , . , .

+2

Source: https://habr.com/ru/post/1693285/


All Articles