# CMake Error: install(EXPORT) generated target "mylib" but target "mylib" has library output path "/build/lib" that does not match the install destination "/usr/local/lib"

- **ID:** `cmake/export-library-path-mismatch`
- **Domain:** cmake
- **Category:** install_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

The target's LIBRARY_OUTPUT_DIRECTORY or ARCHIVE_OUTPUT_DIRECTORY differs from the DESTINATION specified in install(TARGETS), causing CMake to detect a mismatch during export generation.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| cmake 3.26.0 | active | — | — |
| cmake 3.27.0 | active | — | — |
| cmake 3.28.0 | active | — | — |

## Workarounds

1. **Set the target's output directory to match the install destination using generator expressions:

set_target_properties(mylib PROPERTIES
  LIBRARY_OUTPUT_DIRECTORY "${CMAKE_INSTALL_PREFIX}/lib"
  ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_INSTALL_PREFIX}/lib"
)

Then ensure install(TARGETS mylib DESTINATION lib) matches.** (90% success)
   ```
   Set the target's output directory to match the install destination using generator expressions:

set_target_properties(mylib PROPERTIES
  LIBRARY_OUTPUT_DIRECTORY "${CMAKE_INSTALL_PREFIX}/lib"
  ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_INSTALL_PREFIX}/lib"
)

Then ensure install(TARGETS mylib DESTINATION lib) matches.
   ```
2. **Use a relative path in install(DESTINATION) that matches the build output:

set_target_properties(mylib PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
install(TARGETS mylib DESTINATION "${CMAKE_BINARY_DIR}/lib")

Then generate the export with install(EXPORT ... DESTINATION "${CMAKE_BINARY_DIR}/lib")** (85% success)
   ```
   Use a relative path in install(DESTINATION) that matches the build output:

set_target_properties(mylib PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
install(TARGETS mylib DESTINATION "${CMAKE_BINARY_DIR}/lib")

Then generate the export with install(EXPORT ... DESTINATION "${CMAKE_BINARY_DIR}/lib")
   ```

## Dead Ends

- **Change LIBRARY_OUTPUT_DIRECTORY to match the install destination** — LIBRARY_OUTPUT_DIRECTORY affects build-time output, not install; changing it may break build scripts or tests that expect the library in the original build directory. (60% fail)
- **Remove install(EXPORT) entirely** — Removes the export mechanism, so downstream projects using find_package will fail to locate the package. (90% fail)
