Linking a shared library against a static library: must the static library be compiled differently than if an application were linking it?

You do not have to use PIC code in shared objects (as you have discovered you can use the -mimpure-text option to allow that). That said, non-PIC code in shared objects are more heavyweight. With PIC code, the text pages in memory are just direct memory mappings of the text pages on disk. This means … Read more

What is the difference between `-fpic` and `-fPIC` gcc parameters?

http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html Use `-fPIC` or `-fpic` to generate position independent code. Whether to use `-fPIC` or `-fpic` to generate position independent code is target-dependent. The `-fPIC` choice always works, but may produce larger code than `-fpic` (mnemonic to remember this is that PIC is in a larger case, so it may produce larger amounts of code). … Read more

What does -fPIC mean when building a shared library?

PIC stands for Position Independent Code. 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 AArch64, m68k, PowerPC and SPARC. Use this when building shared objects (*.so) on those … Read more

GCC -fPIC option

Position Independent Code means that the generated machine code is not dependent on being located at a specific address in order to work. E.g. jumps would be generated as relative rather than absolute. Pseudo-assembly: PIC: This would work whether the code was at address 100 or 1000 100: COMPARE REG1, REG2 101: JUMP_IF_EQUAL CURRENT+10 … … Read more