What does -fPIC mean when building a shared library?

Sasha picture Sasha · Jun 8, 2009 · Viewed 57.8k times · Source

I know the '-fPIC' option has something to do with resolving addresses and independence between individual modules, but I'm not sure what it really means. Can you explain?

Answer

sean riley picture sean riley · Jun 8, 2009

PIC stands for Position Independent Code

and to quote man gcc:

If supported for the target machine, emit position-independent code, suitable for dynamic linking and avoiding any limit on the size of the global offset table. This option makes a difference on the m68k, PowerPC and SPARC. Position-independent code requires special support, and therefore works only on certain machines.

use this when building shared objects (*.so) on those mentioned architectures.