# CMake Error: install RPATH file /usr/local/lib/libfoo.so not found in build tree. RPATH settings may be incorrect.

- **ID:** `cmake/install-rpath-missing`
- **Domain:** cmake
- **Category:** install_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The INSTALL_RPATH property of a target references a library path that does not exist in the build tree, often due to a typo or using an absolute path from the host system instead of a build-relative path.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| CMake 3.0+ | active | — | — |
| Linux x86_64 | active | — | — |

## Workarounds

1. **Correct the INSTALL_RPATH property to use build-relative paths. For example, if the library is in ${CMAKE_BINARY_DIR}/lib, set: set_target_properties(mytarget PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib").** (90% success)
   ```
   Correct the INSTALL_RPATH property to use build-relative paths. For example, if the library is in ${CMAKE_BINARY_DIR}/lib, set: set_target_properties(mytarget PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib").
   ```
2. **Use generator expressions to set RPATH conditionally: set_target_properties(mytarget PROPERTIES INSTALL_RPATH "$ORIGIN/../lib"). This uses the installed binary's location.** (95% success)
   ```
   Use generator expressions to set RPATH conditionally: set_target_properties(mytarget PROPERTIES INSTALL_RPATH "$ORIGIN/../lib"). This uses the installed binary's location.
   ```
3. **Remove the incorrect INSTALL_RPATH and rely on CMake's default RPATH handling: just remove the set_target_properties line and reconfigure.** (80% success)
   ```
   Remove the incorrect INSTALL_RPATH and rely on CMake's default RPATH handling: just remove the set_target_properties line and reconfigure.
   ```

## Dead Ends

- **Set CMAKE_SKIP_RPATH to ON to skip RPATH processing entirely** — Skips the check but may cause runtime failures because the installed binary cannot find its shared libraries. (70% fail)
- **Manually create the missing file as a symlink** — The build tree is ephemeral; symlinks break after clean build. Also, the error is about the path not existing, not the file. (85% fail)
- **Change INSTALL_RPATH to use $ORIGIN (relative path)** — While this is a good practice, simply changing to $ORIGIN without correcting the actual path still fails if the path is malformed. (50% fail)
