I've already read the gcc
manpage, but I still can't understand the difference between -fpic
and -fPIC
. Can someone explain it, in a very simple and clear way?
Related questions:
fPIC option in GCC enables the address of shared libraries to be relative so that the executable is independent of the position of libraries. This enables one to share built library which has dependencies on other shared libraries. fPIC stands for "force Position Independent Code".
-fpic Generate position-independent code (PIC) suitable for use in a shared library, if supported for the target machine. Such code accesses all constant addresses through a global offset table (GOT).
gcc -fPIC generates position independent code (PIC) for shared libraries.
In computing, position-independent code (PIC) or position-independent executable (PIE) is a body of machine code that, being placed somewhere in the primary memory, executes properly regardless of its absolute address.
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). Using `-fpic` option usually generates smaller and faster code, but will have platform-dependent limitations, such as the number of globally visible symbols or the size of the code. The linker will tell you whether it fits when you create the shared library. When in doubt, I choose `-fPIC`, because it always works.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With