GCC Linker Error: relocation R_X86_64_PC32 / R_AARCH64_ADR_PREL cannot be used; recompile with -fPIC
Static library compiled without Position-Independent Code (`-fPIC`) was linked into a `.so` shared library.
Runs locally in browser
Free · No login
Independently Verified 2026-11-25
v4.1.0
Identifier: GCC Linker Error
Platform: C/C++
Common Root Causes:
- Static library compiled without Position-Independent Code (`-fPIC`) was linked into a `.so` shared library.
Interactive Diagnostic Checklist
Verified Solutions:
- Rebuild static dependency with `-fPIC` (`set(CMAKE_POSITION_INDEPENDENT_CODE ON)` in CMake).
Safe Diagnostic Command:
Check CMAKE_POSITION_INDEPENDENT_CODE
Warning: Verify configuration changes in staging or with dry-run flags (e.g. nginx -t) before reloading production services.
Technical Explanation
Static library compiled without Position-Independent Code (`-fPIC`) was linked into a `.so` shared library. Recommended diagnostic: `Check CMAKE_POSITION_INDEPENDENT_CODE`. Remediation: Rebuild static dependency with `-fPIC` (`set(CMAKE_POSITION_INDEPENDENT_CODE ON)` in CMake).
Worked Examples
- Run `Check CMAKE_POSITION_INDEPENDENT_CODE` to verify root cause before applying the remediation.
Limitations & Assumptions
- Always verify configuration changes in staging or with dry-run flags (e.g. `nginx -t`) before reloading production services.
Source References & Verification
Resource ID: err-cpp-fpic-relocation-shared-lib · Independently verified: 2026-11-25