# CMake Error: Target 'mylib' has INTERFACE_LIBRARY type but target_link_libraries was called with non-INTERFACE keyword

- **ID:** `cmake/target-links-interface-libraries-with-non-interface-keyword`
- **Domain:** cmake
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 95%

## Root Cause

A target defined as INTERFACE (header-only) library must only use INTERFACE keyword in target_link_libraries, but PRIVATE or PUBLIC was used.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| CMake 3.20 | active | — | — |
| CMake 3.22 | active | — | — |
| CMake 3.28 | active | — | — |

## Workarounds

1. **Replace PUBLIC with INTERFACE in target_link_libraries for the INTERFACE library** (100% success)
   ```
   Replace PUBLIC with INTERFACE in target_link_libraries for the INTERFACE library
   ```
2. **Convert the INTERFACE library to a STATIC library with a dummy source file if link dependencies are needed** (80% success)
   ```
   Convert the INTERFACE library to a STATIC library with a dummy source file if link dependencies are needed
   ```
3. **Use target_link_options instead of target_link_libraries for compiler-specific flags** (70% success)
   ```
   Use target_link_options instead of target_link_libraries for compiler-specific flags
   ```

## Dead Ends

- **Change the target type to STATIC or SHARED** — Changing target type may break the build if the library is meant to be header-only. (50% fail)
- **Use PUBLIC keyword but add dummy source files** — PUBLIC is still not allowed for INTERFACE libraries; only INTERFACE keyword is valid. (90% fail)
- **Remove all target_link_libraries calls** — This may lose necessary link dependencies for consumers of the header-only library. (30% fail)
