# CMake Error: Target 'mylib' requires PIC mode but its dependency 'otherlib' is built without PIC. Reconfigure otherlib with CMAKE_POSITION_INDEPENDENT_CODE=ON.

- **ID:** `cmake/abi-mismatch-pic`
- **Domain:** cmake
- **Category:** build_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

A shared library target requires position-independent code (PIC), but a static library dependency was built without PIC, causing linker errors or ABI incompatibility.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| CMake 3.10+ | active | — | — |
| GCC 9.3.0 | active | — | — |

## Workarounds

1. **Set PIC on the dependency target explicitly: set_target_properties(otherlib PROPERTIES POSITION_INDEPENDENT_CODE ON). Then reconfigure.** (95% success)
   ```
   Set PIC on the dependency target explicitly: set_target_properties(otherlib PROPERTIES POSITION_INDEPENDENT_CODE ON). Then reconfigure.
   ```
2. **In CMakeLists.txt, before add_library for otherlib, set: set(CMAKE_POSITION_INDEPENDENT_CODE ON). This ensures all subsequent static libraries are built with PIC.** (90% success)
   ```
   In CMakeLists.txt, before add_library for otherlib, set: set(CMAKE_POSITION_INDEPENDENT_CODE ON). This ensures all subsequent static libraries are built with PIC.
   ```
3. **If otherlib is an external package, rebuild it with -DCMAKE_POSITION_INDEPENDENT_CODE=ON flag during its own CMake configure step.** (85% success)
   ```
   If otherlib is an external package, rebuild it with -DCMAKE_POSITION_INDEPENDENT_CODE=ON flag during its own CMake configure step.
   ```

## Dead Ends

- **Add -fPIC manually to target_compile_options for otherlib** — CMake's PIC handling is more nuanced; manual flags may conflict with CMake's own POSITION_INDEPENDENT_CODE property. (60% fail)
- **Set CMAKE_POSITION_INDEPENDENT_CODE globally to ON** — Forces PIC on all targets, which may break performance on some architectures (e.g., x86-64) and is not always desired. (40% fail)
- **Change mylib to STATIC library to avoid PIC requirement** — If mylib must be shared (e.g., for plugin loading), this changes the library type and may break downstream consumers. (70% fail)
