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 ... 111: NOP
Non-PIC: This will only work if the code is at address 100
100: COMPARE REG1, REG2 101: JUMP_IF_EQUAL 111 ... 111: NOP
EDIT: In response to comment.
If your code is compiled with -fPIC, it’s suitable for inclusion in a library – the library must be able to be relocated from its preferred location in memory to another address, there could be another already loaded library at the address your library prefers.
Related Posts:
- What is the difference between g++ and gcc?
- g++ ld: symbol(s) not found for architecture x86_64
- Convert char to int in C and C++
- Undefined reference to vtable
- Expected initializer before function name
- Inheriting constructors
- Undefined reference to vtable
- C ++ error: a expected initializer before [function name]
- Inheriting constructors
- undefined reference to ‘std::cout’
- Fatal error: iostream: No such file or directory in compiling C program using GCC
- MinGW: “gcc is not recognized as an internal or external command”
- Compiling a C++ program with gcc
- gcc/g++: “No such file or directory”
- error: use of deleted function
- CMake error at CMakeLists.txt:30 (project): No CMAKE_C_COMPILER could be found
- cannot declare variable ‘’ to be of abstract type ‘’
- Debug vs Release in CMake
- Debug vs Release in CMake
- What does the fpermissive flag do?
- gcc: undefined reference to
- Update GCC on OSX
- gcc -g :what will happen
- Warning : overflow in implicit constant conversion
- cc1.exe System Error – libwinpthread-1.dll missing – But it isn’t
- Fatal error: iostream: No such file or directory in compiling C program using GCC
- How to Check the Version of my gcc?
- Make / gcc cryptic error 2: how to have more information?
- Linker error: “linker input file unused because linking not done”, undefined reference to a function in that file
- What is a segmentation fault?
- Return array in a function
- Regular cast vs. static_cast vs. dynamic_cast
- What is an unsigned char?
- C++ std::priority_queue uses the lambda expression
- When to use reinterpret_cast?
- Expression must be a modifiable lvalue
- How to read a file line by line or a whole text file at once?
- Split a string using C++11
- error: expected unqualified-id error: Meaning and fix? [duplicate]
- How to track down a “double free or corruption” error
- Graphics Library for C++
- ‘cout’ was not declared in this scope
- What is the difference between const int*, const int * const, and int const *?
- TranslateName() function doesn’t work on win10
- How to use the PI constant in C++
- How to concatenate two strings in C++?
- How to get current time and date in C++?
- where is the official c++ documentation
- wntdll.pdb not loaded – Can’t see the exception
- Networking with C++
- C++ Structure Initialization
- expression preceding parentheses of apparent call must have (pointer-to-) function type
- Enum to String C++
- Random float number generation
- C++ terminate called without an active exception
- Convert Python program to C/C++ code?
- How to debug ‘Stack smashing detected’?
- basic_string::_M_construct null not valid after constructing subvector of strings
- Does C++ have a Garbage Collector?
- Is “argv[0] = name-of-executable” an accepted standard or just a common convention?
- How to fix ‘std::logic_error’ what(): basic_string::_M_construct null not valid error?
- warning: control reaches end of non-void function [-Wreturn-type]
- Program received signal SIGSEGV, Segmentation fault
- Error: expected type-specifier before ‘ClassName’
- General way of solving Error: Stack around the variable ‘x’ was corrupted
- error MSB3073: How do I fix this?
- timestamp of time(0) at multiple places in a C++ program
- Error “system” is ambiguous?
- What does “Permission denied” “Id returned 1 exit status” mean?
- When does an Incomplete Type error occur in C++
- std::cin input with spaces?
- extended initializer lists only available with
- how to initialize an empty integer array in c++
- What does |= mean in c++
- Error: cannot declare variable ‘c’ to be of abstract type ‘circle’
- C++ Error: Type Name is Not Allowed
- Is Python faster and lighter than C++?
- Case insensitive string comparison C++
- C++ Exception thrown: read access violation. this was nullptr
- C++ getInt() function (have a java equivalent attached)
- Simple string parsing with C++
- member access within null pointer of type ‘struct ListNode’
- How does c++ represent negative value
- Converting String to Cstring in C++
- creating dynamic array of string c++
- How well is Unicode supported in C++11?
- The CXX compiler identification is unknown
- Is there a standard sign function (signum, sgn) in C/C++?
- C++ compiler error: “return type specification for constructor invalid”
- error: ISO C++ forbids in-class initialization of non-const static member
- Function call missing argument list to create pointer
- “No rule to make target ‘install'”… But Makefile exists
- How to determine the version of the C++ standard used by the compiler?
- REGSVR32: the module “xxxxx.dll” failed to load … dependent assembly could not be found
- Error: expression cannot be used as a function?
- What is a .h.gch file?
- MinGW .exe requires a few gcc dll’s regardless of the code?
- Converting bool to text in C++
- Template constructor in a class template – how to explicitly specify template argument for the 2nd parameter?
- C++ float array initialization