cmake
build_error
ai_generated
true
CMake Error: Cannot specify link libraries for target which is not built by this project
ID: cmake/target-link-unknown
90%Fix Rate
88%Confidence
3Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3 | active | — | — | — |
Root Cause
target_link_libraries references a nonexistent target. Typo or wrong order in CMakeLists.txt.
genericWorkarounds
-
95% success Ensure add_executable is called before target_link_libraries
add_executable(my_target main.cpp) target_link_libraries(my_target PRIVATE my_lib)
Sources: https://cmake.org/cmake/help/latest/
-
90% success Check for typos between add_executable and target_link_libraries
-
85% success If target is in subdirectory, call add_subdirectory first
Dead Ends
Common approaches that don't work:
-
Use add_custom_target to make it visible
78% fail
add_custom_target is for custom commands, not linkable libraries
-
Move target_link_libraries before add_executable
85% fail
Target must exist before setting properties. add_executable must come FIRST.