Skip to content
Latchkey

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
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

  1. Add or move the find_package call above the target_link_libraries.
  2. Request the components that define the target you link.
  3. Install the -dev package so find_package actually succeeds.
CMakeLists.txt
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.

Terminal
sudo apt-get install -y libssl-dev
cmake -S . -B build

How 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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →