Skip to content
Latchkey

CMake "target_link_libraries called with incorrect number of arguments" in CI

target_link_libraries needs a valid target followed by libraries, and you cannot mix the keyword form (PRIVATE/PUBLIC) with the plain form on the same target. A malformed call triggers this.

What this error means

Configure fails with "target_link_libraries called with incorrect number of arguments", often when the target name is empty or a variable expanded to nothing.

cmake
CMake Error at CMakeLists.txt:12 (target_link_libraries):
  target_link_libraries called with incorrect number of arguments

Common causes

How to fix it

Use a single, complete signature

  1. Pass a defined target then a scope keyword and the libraries.
  2. Do not combine keyword and plain forms for the same target.
cmake
target_link_libraries(app PRIVATE fmt::fmt Threads::Threads)

How to prevent it

  • Always use the keyword signature consistently and confirm the target variable is set before calling target_link_libraries.

Related guides

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