CMake "target links to target X but the target was not found" in CI
A target_link_libraries call names an imported target (like OpenSSL::SSL) that does not exist. Usually the matching find_package was skipped, failed quietly, or ran with the wrong components, so the target was never defined.
What this error means
Configuration fails with "Target \"app\" links to target \"Foo::Foo\" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing?".
CMake Error at CMakeLists.txt:12 (target_link_libraries):
Target "app" links to target "OpenSSL::SSL" but the target was not found.
Perhaps a find_package() call is missing for an IMPORTED target, or an
ALIAS target is missing?Common causes
The find_package for that target was not called
The imported target only exists after a successful find_package; without it the link target is undefined.
find_package succeeded but did not export that target
The wrong components were requested, or the dependency version is too old to provide the namespaced target.
How to fix it
Call find_package before linking
- Add or move the
find_packagecall above thetarget_link_libraries. - Request the components that define the target you link.
- Install the -dev package so find_package actually succeeds.
find_package(OpenSSL REQUIRED)
target_link_libraries(app PRIVATE OpenSSL::SSL)Ensure the dependency is found first
A quiet find_package failure leaves the target undefined; mark it REQUIRED so configure fails at the real cause.
sudo apt-get install -y libssl-dev
cmake -S . -B buildHow to prevent it
- Mark find_package REQUIRED so missing deps fail loudly and early.
- Order find_package before target_link_libraries.
- Install the -dev package that provides the imported target.