Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

gcc

fpic

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:

  • What does -fPIC mean when building a shared library?
  • What, if any, are the implications of compiling objects with gcc -fPIC flag if they get used in executables?
like image 362
Denilson Sá Maia Avatar asked Aug 23 '10 00:08

Denilson Sá Maia


People also ask

What is fPIC option in GCC?

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".

What is fPIC command?

-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).

What is PIC GCC?

gcc -fPIC generates position independent code (PIC) for shared libraries.

What is position independent code Linux?

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.


1 Answers

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.
like image 106
Anycorn Avatar answered Oct 13 '22 23:10

Anycorn